Skip to content

Commit

Permalink
chore: fix mypy errs (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Feb 16, 2024
1 parent 6f9efc3 commit 601df5f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion a_sync/_bound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion a_sync/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@overload
def a_sync(
**modifiers: Unpack[ModifierKwargs],
) -> AnyFn[P, T]:...
) -> ASyncDecorator:...

@overload # async def, None default
def a_sync(
Expand Down
10 changes: 5 additions & 5 deletions a_sync/modified.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions a_sync/modifiers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion a_sync/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 601df5f

Please sign in to comment.