@@ -54,7 +54,7 @@ def __init__(self, service: Inject[Service]) -> None:
5454@pytest .mark .parametrize (
5555 ('enabled' , 'expected' ),
5656 [
57- (True , { '4:0 ' + TC002 . format ( module = 'other_dependency.OtherDependency' )} ),
57+ (True , set () ),
5858 (
5959 False ,
6060 {
@@ -65,8 +65,8 @@ def __init__(self, service: Inject[Service]) -> None:
6565 ),
6666 ],
6767)
68- def test_injector_option_only_allows_injected_dependencies (enabled , expected ):
69- """Whenever an injector option is enabled, only injected dependencies should be ignored ."""
68+ def test_injector_option_all_annotations_in_function_are_runtime_dependencies (enabled , expected ):
69+ """Whenever an argument is injected, all the other annotations are runtime required too ."""
7070 example = textwrap .dedent (
7171 '''
7272 from injector import Inject
@@ -82,38 +82,20 @@ def __init__(self, service: Inject[Service], other: OtherDependency) -> None:
8282 assert _get_error (example , error_code_filter = 'TC002' , type_checking_injector_enabled = enabled ) == expected
8383
8484
85- @pytest .mark .parametrize (
86- ('enabled' , 'expected' ),
87- [
88- (True , {'4:0 ' + TC002 .format (module = 'other_dependency.OtherDependency' )}),
89- (
90- False ,
91- {
92- '2:0 ' + TC002 .format (module = 'injector.Inject' ),
93- '3:0 ' + TC002 .format (module = 'services.Service' ),
94- '4:0 ' + TC002 .format (module = 'other_dependency.OtherDependency' ),
95- },
96- ),
97- ],
98- )
99- def test_injector_option_only_allows_injector_slices (enabled , expected ):
100- """
101- Whenever an injector option is enabled, only injected dependencies should be ignored,
102- not any dependencies with slices.
103- """
85+ def test_injector_option_require_injections_under_unpack ():
86+ """Whenever an injector option is enabled, injected dependencies should be ignored, even if unpacked."""
10487 example = textwrap .dedent (
10588 """
89+ from typing import Unpack
10690 from injector import Inject
107- from services import Service
108- from other_dependency import OtherDependency
109-
91+ from services import ServiceKwargs
11092 class X:
111- def __init__(self, service: Inject[Service], other_deps: list[OtherDependency ]) -> None:
93+ def __init__(self, service: Inject[Service], **kwargs: Unpack[ServiceKwargs ]) -> None:
11294 self.service = service
113- self.other_deps = other_deps
95+ self.args = args
11496 """
11597 )
116- assert _get_error (example , error_code_filter = 'TC002' , type_checking_injector_enabled = enabled ) == expected
98+ assert _get_error (example , error_code_filter = 'TC002' , type_checking_injector_enabled = True ) == set ()
11799
118100
119101@pytest .mark .parametrize (
0 commit comments