Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: some low-hanging fruit on the strict type check #3416

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .github/pyright-config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"include": [
"type_check.py",
"../BizHawkClient.py",
"../Patch.py",
"../test/general/test_groups.py",
"../test/general/test_helpers.py",
"../test/general/test_memory.py",
"../test/general/test_names.py",
"../test/multiworld/__init__.py",
"../test/multiworld/test_multiworlds.py",
"../test/netutils/__init__.py",
"../test/programs/__init__.py",
"../test/programs/test_multi_server.py",
"../test/utils/__init__.py",
"../test/webhost/test_descriptions.py",
"../worlds/AutoSNIClient.py",
"../Patch.py"
"type_check.py"
],

"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/strict-type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- name: "Install dependencies"
run: |
python -m pip install --upgrade pip pyright==1.1.358
python -m pip install --upgrade pip pyright==1.1.377
python ModuleUpdate.py --append "WebHostLib/requirements.txt" --force --yes

- name: "pyright: strict check on specific files"
Expand Down
11 changes: 7 additions & 4 deletions test/general/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import unittest
from typing import Callable, Dict, Optional

from typing_extensions import override

from BaseClasses import CollectionState, MultiWorld, Region


class TestHelpers(unittest.TestCase):
multiworld: MultiWorld
player: int = 1

@override
def setUp(self) -> None:
self.multiworld = MultiWorld(self.player)
self.multiworld.game[self.player] = "helper_test_game"
Expand Down Expand Up @@ -38,15 +41,15 @@ def test_region_helpers(self) -> None:
"TestRegion1": {"TestRegion2": "connection"},
"TestRegion2": {"TestRegion1": None},
}

reg_exit_set: Dict[str, set[str]] = {
"TestRegion1": {"TestRegion3"}
}

exit_rules: Dict[str, Callable[[CollectionState], bool]] = {
"TestRegion1": lambda state: state.has("test_item", self.player)
}

self.multiworld.regions += [Region(region, self.player, self.multiworld, regions[region]) for region in regions]

with self.subTest("Test Location Creation Helper"):
Expand All @@ -73,7 +76,7 @@ def test_region_helpers(self) -> None:
entrance_name = exit_name if exit_name else f"{parent} -> {exit_reg}"
self.assertEqual(exit_rules[exit_reg],
self.multiworld.get_entrance(entrance_name, self.player).access_rule)

for region in reg_exit_set:
current_region = self.multiworld.get_region(region, self.player)
current_region.add_exits(reg_exit_set[region])
Expand Down
2 changes: 1 addition & 1 deletion test/general/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class TestWorldMemory(unittest.TestCase):
def test_leak(self):
def test_leak(self) -> None:
"""Tests that worlds don't leak references to MultiWorld or themselves with default options."""
import gc
import weakref
Expand Down
4 changes: 2 additions & 2 deletions test/general/test_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@


class TestNames(unittest.TestCase):
def test_item_names_format(self):
def test_item_names_format(self) -> None:
"""Item names must not be all numeric in order to differentiate between ID and name in !hint"""
for gamename, world_type in AutoWorldRegister.world_types.items():
with self.subTest(game=gamename):
for item_name in world_type.item_name_to_id:
self.assertFalse(item_name.isnumeric(),
f"Item name \"{item_name}\" is invalid. It must not be numeric.")

def test_location_name_format(self):
def test_location_name_format(self) -> None:
"""Location names must not be all numeric in order to differentiate between ID and name in !hint_location"""
for gamename, world_type in AutoWorldRegister.world_types.items():
with self.subTest(game=gamename):
Expand Down
Loading