From 2cd11918b108b8c4239d6392b584b1d59fc2fafc Mon Sep 17 00:00:00 2001 From: Ricardo Busquet Date: Wed, 31 Jan 2024 14:27:04 -0500 Subject: [PATCH] more tests --- injector_test.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/injector_test.py b/injector_test.py index 8a93872..323a250 100644 --- a/injector_test.py +++ b/injector_test.py @@ -1800,3 +1800,35 @@ class Data: injector = Injector([configure]) assert injector.get(Data).user_id == 123 + + +def test_annotated_in_injection_configuration(): + UserID = Annotated[int, "user_id"] + + def configure(binder): + binder.bind(UserID, to=123) + + @inject + @dataclass + class Data: + user_id: Annotated[int, "user_id"] + + injector = Injector([configure]) + + assert injector.get(Data).user_id == 123 + + +def test_bind_to_annotated_directly(): + def configure(binder): + # works at runtime, mypy complains: + # Argument 1 to "bind" of "Binder" has incompatible type "object"; expected "type[str]" + binder.bind(Annotated[int, "user_id"], to=123) + + @inject + @dataclass + class Data: + user_id: Annotated[int, "user_id"] + + injector = Injector([configure]) + + assert injector.get(Data).user_id == 123