@@ -217,25 +217,70 @@ def test_package_existed_helper():
217
217
assert not _utils ._package_existed ([], "pandas" )
218
218
219
219
220
+ # Helper functions for signature inspection tests
221
+ def _func_one_arg_annotated (x : int ) -> int :
222
+ """A function with one annotated arg and an annotated return type."""
223
+ return x
224
+
225
+
226
+ def _func_one_arg_unannotated (x ):
227
+ """A function with one unannotated arg and no return type annotation."""
228
+ return x
229
+
230
+
231
+ def _func_two_args_annotated (x : int , y : str ):
232
+ """A function with two annotated args and no return type annotation."""
233
+ return f"{ x } { y } "
234
+
235
+
236
+ def _func_two_args_unannotated (x , y ):
237
+ """A function with two unannotated args and no return type annotation."""
238
+ return f"{ x } { y } "
239
+
240
+
241
+ def test_has_conflict_input_type_too_few_inputs ():
242
+ """Tests conflict when there are fewer input types than parameters."""
243
+ signature = inspect .signature (_func_one_arg_annotated )
244
+ assert _utils .has_conflict_input_type (signature , input_types = [])
245
+
246
+
247
+ def test_has_conflict_input_type_too_many_inputs ():
248
+ """Tests conflict when there are more input types than parameters."""
249
+ signature = inspect .signature (_func_one_arg_annotated )
250
+ assert _utils .has_conflict_input_type (signature , input_types = [int , str ])
251
+
252
+
253
+ def test_has_conflict_input_type_type_mismatch ():
254
+ """Tests has_conflict_input_type with a conflicting type annotation."""
255
+ signature = inspect .signature (_func_two_args_annotated )
256
+
257
+ # The second type (bool) conflicts with the annotation (str).
258
+ assert _utils .has_conflict_input_type (signature , input_types = [int , bool ])
259
+
260
+
261
+ def test_has_conflict_input_type_no_conflict_annotated ():
262
+ """Tests that a matching, annotated signature is compatible."""
263
+ signature = inspect .signature (_func_two_args_annotated )
264
+ assert not _utils .has_conflict_input_type (signature , input_types = [int , str ])
265
+
266
+
267
+ def test_has_conflict_input_type_no_conflict_unannotated ():
268
+ """Tests that a signature with no annotations is always compatible."""
269
+ signature = inspect .signature (_func_two_args_unannotated )
270
+ assert not _utils .has_conflict_input_type (signature , input_types = [int , float ])
271
+
272
+
220
273
def test_has_conflict_output_type_no_conflict ():
221
274
"""Tests has_conflict_output_type with type annotation."""
222
- # Helper functions with type annotation for has_conflict_output_type.
223
- def _func_with_return_type (x : int ) -> int :
224
- return x
225
-
226
- signature = inspect .signature (_func_with_return_type )
275
+ signature = inspect .signature (_func_one_arg_annotated )
227
276
228
277
assert _utils .has_conflict_output_type (signature , output_type = float )
229
278
assert not _utils .has_conflict_output_type (signature , output_type = int )
230
279
231
280
232
281
def test_has_conflict_output_type_no_annotation ():
233
282
"""Tests has_conflict_output_type without type annotation."""
234
- # Helper functions without type annotation for has_conflict_output_type.
235
- def _func_without_return_type (x ):
236
- return x
237
-
238
- signature = inspect .signature (_func_without_return_type )
283
+ signature = inspect .signature (_func_one_arg_unannotated )
239
284
240
285
assert not _utils .has_conflict_output_type (signature , output_type = int )
241
286
assert not _utils .has_conflict_output_type (signature , output_type = float )
0 commit comments