Skip to content

Commit

Permalink
Fix type check errors
Browse files Browse the repository at this point in the history
  • Loading branch information
layday committed May 18, 2024
1 parent 77e95d7 commit 7d25a86
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 32 deletions.
13 changes: 9 additions & 4 deletions instawow-gui/src/instawow_gui/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# pyright: reportMissingParameterType = false
# pyright: reportUnknownArgumentType = false
# pyright: reportUnknownParameterType = false
# pyright: reportUnknownMemberType = false

from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -86,7 +91,7 @@ def dispatch_js_keyboard_event(command: toga.Command, **kwargs):
),
text='Toggle Search Filter',
shortcut=toga.Key.MOD_1 + toga.Key.G,
group=toga.Group.EDIT,
group=toga.Group.EDIT, # pyright: ignore[reportArgumentType]
section=20,
order=10,
),
Expand All @@ -99,7 +104,7 @@ def dispatch_js_keyboard_event(command: toga.Command, **kwargs):
),
text='Installed',
shortcut=toga.Key.MOD_1 + toga.Key.L,
group=toga.Group.WINDOW,
group=toga.Group.WINDOW, # pyright: ignore[reportArgumentType]
section=20,
order=10,
),
Expand All @@ -111,7 +116,7 @@ def dispatch_js_keyboard_event(command: toga.Command, **kwargs):
action=_TogaSimulateKeypressAction.ActivateViewReconcile,
),
text='Unreconciled',
group=toga.Group.WINDOW,
group=toga.Group.WINDOW, # pyright: ignore[reportArgumentType]
section=20,
order=20,
),
Expand All @@ -124,7 +129,7 @@ def dispatch_js_keyboard_event(command: toga.Command, **kwargs):
),
text='Search',
shortcut=toga.Key.MOD_1 + toga.Key.F,
group=toga.Group.WINDOW,
group=toga.Group.WINDOW, # pyright: ignore[reportArgumentType]
section=20,
order=30,
),
Expand Down
2 changes: 1 addition & 1 deletion instawow-gui/src/instawow_gui_wrapper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def _patch_std_streams() -> None:
import sys

# These are ``None`` when pythonw is used.
if sys.stdout is None or sys.stderr is None:
if sys.stdout is None or sys.stderr is None: # pyright: ignore[reportUnnecessaryComparison]
sys.stdout = sys.stderr = io.StringIO()


Expand Down
11 changes: 7 additions & 4 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"include": ["src", "instawow-gui/src", "tests/plugin"],
"ignore": ["src/instawow/_migrations"],
"include": [
"src",
"instawow-gui/src",
"tests/plugin"
],
"strict": [
"src",
"instawow-gui/src/instawow_gui/json_rpc_server.py",
"instawow-gui/src",
"tests/plugin"
]
}
}
23 changes: 6 additions & 17 deletions src/instawow/wow_installations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,14 @@
from enum import Enum
from functools import cache
from pathlib import Path
from typing import Protocol, TypedDict
from typing import TypedDict, TypeVar

from typing_extensions import NotRequired, Self, TypeVar
from typing_extensions import NotRequired, Self

from ._utils.compat import StrEnum
from ._utils.iteration import fill

_TEnum = TypeVar('_TEnum', bound=Enum, infer_variance=True)


class _FlavourKeyedEnumMeta(type(Protocol)): # pragma: no cover
def __getitem__(self: type[_FlavourKeyedEnum[_TEnum]], __key: str) -> _TEnum: ...


class _FlavourKeyedEnum(Protocol[_TEnum], metaclass=_FlavourKeyedEnumMeta): # pragma: no cover
Retail: _TEnum
VanillaClassic: _TEnum
Classic: _TEnum
WrathClassic: _TEnum
_TEnum = TypeVar('_TEnum', bound=Enum)


class _FlavourMeta(TypedDict):
Expand Down Expand Up @@ -61,13 +50,13 @@ def __new__(cls, value: str, flavour_meta: _FlavourMeta = _DummyFlavourMeta) ->
def from_flavour_keyed_enum(cls, flavour_keyed_enum: Enum) -> Self:
return cls[flavour_keyed_enum.name]

def to_flavour_keyed_enum(self, flavour_keyed_enum: type[_FlavourKeyedEnum[_TEnum]]) -> _TEnum:
def to_flavour_keyed_enum(self, flavour_keyed_enum: type[_TEnum]) -> _TEnum:
return flavour_keyed_enum[self.name]

def get_flavour_groups(self, affine: bool) -> list[tuple[Flavour, ...] | None]:
match (self, affine):
case (self.Classic, True):
return [(self, self.WrathClassic), None]
case (self.__class__.Classic, True):
return [(self, self.__class__.WrathClassic), None]
case (_, True):
return [(self,), None]
case _:
Expand Down
8 changes: 2 additions & 6 deletions src/instawow_wa_updater/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,14 @@ def make_slug_entry(metadata: _WagoApiResponse, import_string: str):
'init.lua', template_resources.joinpath('init.lua').read_text()
)

interface_version = self._profile_config.game_flavour.to_flavour_keyed_enum(
_TocNumber
).value
interface_version = self._profile_config.game_flavour.to_flavour_keyed_enum(_TocNumber)
addon_version = shasum(data_output, init_output, interface_version)[:7]

toc_tpl = template_resources.joinpath('WeakAurasCompanion.toc').read_text()
write_file(
'WeakAurasCompanion.toc',
toc_tpl.format(
interface=self._profile_config.game_flavour.to_flavour_keyed_enum(
_TocNumber
).value,
interface=self._profile_config.game_flavour.to_flavour_keyed_enum(_TocNumber),
version=addon_version,
),
)
Expand Down

0 comments on commit 7d25a86

Please sign in to comment.