Skip to content

Commit 6043cb1

Browse files
committed
injector_test: Add test demonstrating handling of optional parameters
1 parent 13cf0d9 commit 6043cb1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

injector_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,15 @@ def function11(a: int) -> 'InvalidForwardReference':
16741674
assert get_bindings(function11) == {'a': int}
16751675

16761676

1677+
# This will not inject `None` even if there is a provider configured to provide
1678+
# str | None elsewhere in the graph because `None` is stripped in
1679+
@inject
1680+
def function12(a: str | None):
1681+
pass
1682+
1683+
assert get_bindings(function12) == {'a': str | None}
1684+
1685+
16771686
# Tests https://github.com/alecthomas/injector/issues/202
16781687
@pytest.mark.skipif(sys.version_info < (3, 10), reason="Requires Python 3.10+")
16791688
def test_get_bindings_for_pep_604():

0 commit comments

Comments
 (0)