From 601df5f0a8ac8be54ff52946e944a645280c468b Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 16 Feb 2024 09:48:42 -0500 Subject: [PATCH] chore: fix mypy errs (#128) --- a_sync/_bound.py | 2 +- a_sync/decorator.py | 2 +- a_sync/modified.py | 10 +++++----- a_sync/modifiers/manager.py | 6 +++--- a_sync/property.py | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/a_sync/_bound.py b/a_sync/_bound.py index 2b02bbcd..68ba5952 100644 --- a/a_sync/_bound.py +++ b/a_sync/_bound.py @@ -92,7 +92,7 @@ def _wrap_property( modifiers, _force_await = _clean_default_from_modifiers(async_property, modifiers) @unbound_a_sync(**modifiers) - async def _get(instance: ASyncABC): + async def _get(instance: ASyncABC) -> T: return await async_property.__get__(instance, async_property) @functools.wraps(async_property) diff --git a/a_sync/decorator.py b/a_sync/decorator.py index 5bd2f2d7..f7aab4be 100644 --- a/a_sync/decorator.py +++ b/a_sync/decorator.py @@ -19,7 +19,7 @@ @overload def a_sync( **modifiers: Unpack[ModifierKwargs], -) -> AnyFn[P, T]:... +) -> ASyncDecorator:... @overload # async def, None default def a_sync( diff --git a/a_sync/modified.py b/a_sync/modified.py index d76eb099..ef838695 100644 --- a/a_sync/modified.py +++ b/a_sync/modified.py @@ -30,7 +30,7 @@ def __init__(self, fn: CoroFn[P, T], **modifiers: Unpack[ModifierKwargs]) -> Non def __init__(self, fn: SyncFn[P, T], **modifiers: Unpack[ModifierKwargs]) -> None:... def __init__(self, fn: AnyFn[P, T], **modifiers: Unpack[ModifierKwargs]) -> None: _helpers._validate_wrapped_fn(fn) - self.modifiers = ModifierManager(**modifiers) + self.modifiers = ModifierManager(modifiers) self.__wrapped__ = fn if hasattr(self.__wrapped__, '__name__'): self.__name__ = self.__wrapped__.__name__ @@ -112,16 +112,16 @@ def sync_wrap(*args: P.args, **kwargs: P.kwargs) -> MaybeAwaitable[T]: # type: else: _inherit = ASyncFunction[[AnyFn[P, T]], ASyncFunction[P, T]] -class ASyncDecorator(_inherit): +class ASyncDecorator(_inherit[P, T]): _fn = None def __init__(self, **modifiers: Unpack[ModifierKwargs]) -> None: assert 'default' in modifiers, modifiers - self.modifiers = ModifierManager(**modifiers) + self.modifiers = ModifierManager(modifiers) self.validate_inputs() def validate_inputs(self) -> None: - if self.default not in ['sync', 'async', None]: - raise ValueError(f"'default' must be either 'sync', 'async', or None. You passed {self.default}.") + if self.modifiers.default not in ['sync', 'async', None]: + raise ValueError(f"'default' must be either 'sync', 'async', or None. You passed {self.modifiers.default}.") def __call__(self, func: AnyFn[P, T]) -> ASyncFunction[P, T]: # type: ignore [override] return ASyncFunction(func, **self.modifiers) diff --git a/a_sync/modifiers/manager.py b/a_sync/modifiers/manager.py index 1f469373..d126291f 100644 --- a/a_sync/modifiers/manager.py +++ b/a_sync/modifiers/manager.py @@ -18,7 +18,7 @@ class ModifierManager(Dict[str, Any]): # sync modifiers executor: Executor - def __init__(self, **modifiers: Unpack[ModifierKwargs]) -> None: + def __init__(self, modifiers: ModifierKwargs) -> None: for key in modifiers.keys(): if key not in valid_modifiers: raise ValueError(f"'{key}' is not a supported modifier.") @@ -85,5 +85,5 @@ def __len__(self) -> int: def __getitem__(self, modifier_key: str): return self._modifiers[modifier_key] # type: ignore [literal-required] -nulls = ModifierManager(**null_modifiers) -user_defaults = ModifierManager(**user_set_default_modifiers) +nulls = ModifierManager(null_modifiers) +user_defaults = ModifierManager(user_set_default_modifiers) diff --git a/a_sync/property.py b/a_sync/property.py index d9fceb3b..09d477a7 100644 --- a/a_sync/property.py +++ b/a_sync/property.py @@ -13,7 +13,7 @@ class PropertyDescriptor(Modified[T]): def __init__(self, _fget: Callable[..., T], field_name=None, **modifiers: ModifierKwargs): if not callable(_fget): raise ValueError(f'Unable to decorate {_fget}') - self.modifiers = ModifierManager(**modifiers) + self.modifiers = ModifierManager(modifiers) self._fn = _fget _fget = self.modifiers.apply_async_modifiers(_fget) if asyncio.iscoroutinefunction(_fget) else self._asyncify(_fget) super().__init__(_fget, field_name=field_name) # type: ignore [call-arg]