diff --git a/injector/__init__.py b/injector/__init__.py index 9b52729..9ed43b7 100644 --- a/injector/__init__.py +++ b/injector/__init__.py @@ -1390,7 +1390,7 @@ def provide_strs_also(self) -> List[str]: def _mark_provider_function(function: Callable, *, allow_multi: bool) -> None: scope_ = getattr(function, '__scope__', None) try: - annotations = get_type_hints(function) + annotations = get_type_hints(function, include_extras=True) except NameError: return_type = '__deferred__' else: diff --git a/injector_test.py b/injector_test.py index 6260033..58f311b 100644 --- a/injector_test.py +++ b/injector_test.py @@ -2032,3 +2032,19 @@ class MyClass: injector = Injector([configure]) instance = injector.get(MyClass) assert instance.foo == 123 + + +def test_module_provider_with_annotated(): + class MyModule(Module): + @provider + def provide_first(self) -> Annotated[str, 'first']: + return 'Bob' + + @provider + def provide_second(self) -> Annotated[str, 'second']: + return 'Iger' + + module = MyModule() + injector = Injector(module) + assert injector.get(Annotated[str, 'first']) == 'Bob' + assert injector.get(Annotated[str, 'second']) == 'Iger'