@@ -54,7 +54,7 @@ def __init__(self, service: Inject[Service]) -> None:
54
54
@pytest .mark .parametrize (
55
55
('enabled' , 'expected' ),
56
56
[
57
- (True , { '4:0 ' + TC002 . format ( module = 'other_dependency.OtherDependency' )} ),
57
+ (True , set () ),
58
58
(
59
59
False ,
60
60
{
@@ -65,8 +65,8 @@ def __init__(self, service: Inject[Service]) -> None:
65
65
),
66
66
],
67
67
)
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 ."""
70
70
example = textwrap .dedent (
71
71
'''
72
72
from injector import Inject
@@ -82,38 +82,20 @@ def __init__(self, service: Inject[Service], other: OtherDependency) -> None:
82
82
assert _get_error (example , error_code_filter = 'TC002' , type_checking_injector_enabled = enabled ) == expected
83
83
84
84
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."""
104
87
example = textwrap .dedent (
105
88
"""
89
+ from typing import Unpack
106
90
from injector import Inject
107
- from services import Service
108
- from other_dependency import OtherDependency
109
-
91
+ from services import ServiceKwargs
110
92
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:
112
94
self.service = service
113
- self.other_deps = other_deps
95
+ self.args = args
114
96
"""
115
97
)
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 ()
117
99
118
100
119
101
@pytest .mark .parametrize (
0 commit comments