Skip to content

Commit

Permalink
update mypy version / fix mypy issues (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
stkrizh authored Nov 4, 2024
1 parent 28f8978 commit 8adebe7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dev = [
"pytest-cov",
"pytest-asyncio",
"ruff",
"mypy==1.10.1",
"mypy",
"typing-extensions",
"pre-commit"
]
Expand Down
4 changes: 2 additions & 2 deletions that_depends/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ def reset_override(cls) -> None:
v.reset_override()

@classmethod
def resolver(cls, item: type[T] | typing.Callable[P, T]) -> typing.Callable[[], typing.Awaitable[T]]:
def resolver(cls, item: typing.Callable[P, T]) -> typing.Callable[[], typing.Awaitable[T]]:
async def _inner() -> T:
return await cls.resolve(item)

return _inner

@classmethod
async def resolve(cls, object_to_resolve: type[T] | typing.Callable[..., T]) -> T:
async def resolve(cls, object_to_resolve: typing.Callable[..., T]) -> T:
signature: typing.Final = inspect.signature(object_to_resolve)
kwargs = {}
providers: typing.Final = cls.get_providers()
Expand Down
18 changes: 12 additions & 6 deletions that_depends/providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ async def async_resolve(self) -> T_co:
T_co,
await context.context_stack.enter_async_context(
contextlib.asynccontextmanager(self._creator)(
*[
*[ # type: ignore[arg-type]
await x.async_resolve() if isinstance(x, AbstractProvider) else x
for x in self._args
],
**{
**{ # type: ignore[arg-type]
k: await v.async_resolve() if isinstance(v, AbstractProvider) else v
for k, v in self._kwargs.items()
},
Expand All @@ -195,8 +195,10 @@ async def async_resolve(self) -> T_co:
context.context_stack = contextlib.ExitStack()
context.instance = context.context_stack.enter_context(
contextlib.contextmanager(self._creator)(
*[await x.async_resolve() if isinstance(x, AbstractProvider) else x for x in self._args],
**{
*[ # type: ignore[arg-type]
await x.async_resolve() if isinstance(x, AbstractProvider) else x for x in self._args
],
**{ # type: ignore[arg-type]
k: await v.async_resolve() if isinstance(v, AbstractProvider) else v
for k, v in self._kwargs.items()
},
Expand All @@ -220,8 +222,12 @@ def sync_resolve(self) -> T_co:
context.context_stack = contextlib.ExitStack()
context.instance = context.context_stack.enter_context(
contextlib.contextmanager(self._creator)(
*[x.sync_resolve() if isinstance(x, AbstractProvider) else x for x in self._args],
**{k: v.sync_resolve() if isinstance(v, AbstractProvider) else v for k, v in self._kwargs.items()},
*[ # type: ignore[arg-type]
x.sync_resolve() if isinstance(x, AbstractProvider) else x for x in self._args
],
**{ # type: ignore[arg-type]
k: v.sync_resolve() if isinstance(v, AbstractProvider) else v for k, v in self._kwargs.items()
},
),
)
return typing.cast(T_co, context.instance)
Expand Down
24 changes: 18 additions & 6 deletions that_depends/providers/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,25 @@ async def async_resolve(self) -> T_co:
return typing.cast(T_co, self._override)

return self._factory(
*[await x.async_resolve() if isinstance(x, AbstractProvider) else x for x in self._args],
**{k: await v.async_resolve() if isinstance(v, AbstractProvider) else v for k, v in self._kwargs.items()},
*[ # type: ignore[arg-type]
await x.async_resolve() if isinstance(x, AbstractProvider) else x for x in self._args
],
**{ # type: ignore[arg-type]
k: await v.async_resolve() if isinstance(v, AbstractProvider) else v for k, v in self._kwargs.items()
},
)

def sync_resolve(self) -> T_co:
if self._override:
return typing.cast(T_co, self._override)

return self._factory(
*[x.sync_resolve() if isinstance(x, AbstractProvider) else x for x in self._args],
**{k: v.sync_resolve() if isinstance(v, AbstractProvider) else v for k, v in self._kwargs.items()},
*[ # type: ignore[arg-type]
x.sync_resolve() if isinstance(x, AbstractProvider) else x for x in self._args
],
**{ # type: ignore[arg-type]
k: v.sync_resolve() if isinstance(v, AbstractProvider) else v for k, v in self._kwargs.items()
},
)


Expand All @@ -49,8 +57,12 @@ async def async_resolve(self) -> T_co:
return typing.cast(T_co, self._override)

return await self._factory(
*[await x.async_resolve() if isinstance(x, AbstractProvider) else x for x in self._args],
**{k: await v.async_resolve() if isinstance(v, AbstractProvider) else v for k, v in self._kwargs.items()},
*[ # type: ignore[arg-type]
await x.async_resolve() if isinstance(x, AbstractProvider) else x for x in self._args
],
**{ # type: ignore[arg-type]
k: await v.async_resolve() if isinstance(v, AbstractProvider) else v for k, v in self._kwargs.items()
},
)

def sync_resolve(self) -> typing.NoReturn:
Expand Down
14 changes: 10 additions & 4 deletions that_depends/providers/singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ async def async_resolve(self) -> T_co:
async with self._resolving_lock:
if self._instance is None:
self._instance = self._factory(
*[await x.async_resolve() if isinstance(x, AbstractProvider) else x for x in self._args],
**{
*[ # type: ignore[arg-type]
await x.async_resolve() if isinstance(x, AbstractProvider) else x for x in self._args
],
**{ # type: ignore[arg-type]
k: await v.async_resolve() if isinstance(v, AbstractProvider) else v
for k, v in self._kwargs.items()
},
Expand All @@ -44,8 +46,12 @@ def sync_resolve(self) -> T_co:

if self._instance is None:
self._instance = self._factory(
*[x.sync_resolve() if isinstance(x, AbstractProvider) else x for x in self._args],
**{k: v.sync_resolve() if isinstance(v, AbstractProvider) else v for k, v in self._kwargs.items()},
*[ # type: ignore[arg-type]
x.sync_resolve() if isinstance(x, AbstractProvider) else x for x in self._args
],
**{ # type: ignore[arg-type]
k: v.sync_resolve() if isinstance(v, AbstractProvider) else v for k, v in self._kwargs.items()
},
)
return self._instance

Expand Down

0 comments on commit 8adebe7

Please sign in to comment.