Skip to content

Commit

Permalink
Merge pull request #54 from reagento/fix/self_hint
Browse files Browse the repository at this point in the history
fix self typehint
  • Loading branch information
Tishka17 authored Feb 17, 2024
2 parents 60b5e10 + ea1c61f commit 3736a39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dishka/dependency_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
iscoroutinefunction,
isfunction,
isgeneratorfunction,
signature,
)
from typing import (
Any,
Expand Down Expand Up @@ -117,7 +118,10 @@ def make_factory(
possible_dependency = source
is_to_bind = False
elif isfunction(source):
params = signature(source).parameters
self = next(iter(params.values()))
hints = get_type_hints(source, include_extras=True)
hints.pop(self.name, None)
possible_dependency = hints.pop("return", None)
is_to_bind = True
else:
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,13 @@ def foo(self, x: bool) -> str:

provider = MyProvider(scope=Scope.REQUEST)
assert provider.foo.scope == Scope.REQUEST


def test_self_hint():
class MyProvider(Provider):
@provide
def foo(self: Provider) -> str:
return "hello"

provider = MyProvider(scope=Scope.REQUEST)
assert not provider.foo.dependencies

0 comments on commit 3736a39

Please sign in to comment.