@@ -60,9 +60,15 @@ def squeeze(x, /, axis):
60
60
def _test_inspectable_func (sig : Signature , stub_sig : Signature ):
61
61
params = list (sig .parameters .values ())
62
62
stub_params = list (stub_sig .parameters .values ())
63
+
64
+ non_kwonly_stub_params = [
65
+ p for p in stub_params if p .kind != Parameter .KEYWORD_ONLY
66
+ ]
67
+ # sanity check
68
+ assert non_kwonly_stub_params == stub_params [: len (non_kwonly_stub_params )]
63
69
# We're not interested if the array module has additional arguments, so we
64
70
# only iterate through the arguments listed in the spec.
65
- for i , stub_param in enumerate (stub_params ):
71
+ for i , stub_param in enumerate (non_kwonly_stub_params ):
66
72
assert (
67
73
len (params ) >= i + 1
68
74
), f"Argument '{ stub_param .name } ' missing from signature"
@@ -74,19 +80,24 @@ def _test_inspectable_func(sig: Signature, stub_sig: Signature):
74
80
param .name == stub_param .name
75
81
), f"Expected argument '{ param .name } ' to be named '{ stub_param .name } '"
76
82
77
- f_stub_kind = kind_to_str [stub_param .kind ]
78
83
if stub_param .kind in [Parameter .POSITIONAL_OR_KEYWORD , * VAR_KINDS ]:
84
+ f_stub_kind = kind_to_str [stub_param .kind ]
79
85
assert param .kind == stub_param .kind , (
80
86
f"{ param .name } is a { kind_to_str [param .kind ]} , "
81
87
f"but should be a { f_stub_kind } "
82
88
)
83
- else :
84
- # TODO: allow for kw-only args to be out-of-order
85
- assert param .kind in [stub_param .kind , Parameter .POSITIONAL_OR_KEYWORD ,], (
86
- f"{ param .name } is a { kind_to_str [param .kind ]} , "
87
- f"but should be a { f_stub_kind } "
88
- f"(or at least a { kind_to_str [ParameterKind .POSITIONAL_OR_KEYWORD ]} )"
89
- )
89
+
90
+ kwonly_stub_params = stub_params [len (non_kwonly_stub_params ) :]
91
+ for stub_param in kwonly_stub_params :
92
+ assert (
93
+ stub_param .name in sig .parameters .keys ()
94
+ ), f"Argument '{ stub_param .name } ' missing from signature"
95
+ param = next (p for p in params if p .name == stub_param .name )
96
+ assert param .kind in [stub_param .kind , Parameter .POSITIONAL_OR_KEYWORD ,], (
97
+ f"{ param .name } is a { kind_to_str [param .kind ]} , "
98
+ f"but should be a { f_stub_kind } "
99
+ f"(or at least a { kind_to_str [ParameterKind .POSITIONAL_OR_KEYWORD ]} )"
100
+ )
90
101
91
102
92
103
def get_dtypes_strategy (func_name : str ) -> st .SearchStrategy [DataType ]:
0 commit comments