Skip to content

Commit 1d58fd7

Browse files
AvlWx2014sheinbergon
authored andcommitted
injector_test: Add test demonstrating handling of optional parameters
1 parent d6e0ea4 commit 1d58fd7

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
@@ -1761,6 +1761,15 @@ def function(a: Inject[Inject[int]]) -> None:
17611761
assert get_bindings(function) == {'a': int}
17621762

17631763

1764+
# This will not inject `None` even if there is a provider configured to provide
1765+
# str | None elsewhere in the graph because `None` is stripped in
1766+
@inject
1767+
def function12(a: str | None):
1768+
pass
1769+
1770+
assert get_bindings(function12) == {'a': str | None}
1771+
1772+
17641773
# Tests https://github.com/alecthomas/injector/issues/202
17651774
@pytest.mark.skipif(sys.version_info < (3, 10), reason="Requires Python 3.10+")
17661775
def test_get_bindings_for_pep_604():

0 commit comments

Comments
 (0)