Skip to content

Commit 50e2944

Browse files
committed
test: Separation of types from providers
1 parent f7d3d74 commit 50e2944

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

injector_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def __init__(self, b: EmptyClass):
6969
self.b = b
7070

7171

72+
City = NewType('City', str)
73+
Animal = Annotated[str, 'Animal']
74+
75+
7276
def prepare_nested_injectors():
7377
def configure(binder):
7478
binder.bind(str, to='asd')
@@ -578,6 +582,27 @@ def provide_name(self) -> str:
578582
assert injector.get(str) == 'Bob'
579583

580584

585+
def test_module_provider_keeps_annotated_types_and_new_types_separate() -> None:
586+
class MyModule(Module):
587+
@provider
588+
def provide_name(self) -> str:
589+
return 'Bob'
590+
591+
@provider
592+
def provide_city(self) -> City:
593+
return City('Stockholm')
594+
595+
@provider
596+
def provide_animal(self) -> Animal:
597+
return 'Dog'
598+
599+
module = MyModule()
600+
injector = Injector(module)
601+
assert injector.get(str) == 'Bob'
602+
assert injector.get(City) == City('Stockholm')
603+
assert injector.get(Animal) == 'Dog'
604+
605+
581606
def test_module_class_gets_instantiated():
582607
name = 'Meg'
583608

0 commit comments

Comments
 (0)