Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardo-passthrough committed Jan 31, 2024
1 parent 21a2197 commit 2cd1191
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions injector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2cd1191

Please sign in to comment.