Skip to content

Type-check extra arguments to variadic functions#348

Open
bysiber wants to merge 1 commit intojmespath:developfrom
bysiber:fix/variadic-typecheck
Open

Type-check extra arguments to variadic functions#348
bysiber wants to merge 1 commit intojmespath:developfrom
bysiber:fix/variadic-typecheck

Conversation

@bysiber
Copy link

@bysiber bysiber commented Feb 20, 2026

_type_check only validates the first N arguments where N is the length of the function signature. For variadic functions like merge(), the signature has a single entry with variadic: True, so only the first argument is type-checked. All extra arguments bypass validation entirely.

>>> jmespath.search('merge(`{"a":1}`, `"not_a_dict"`)', {})
# Expected: JMESPathTypeError (string is not an object)
# Actual: ValueError: dictionary update sequence element #0 has length 1

The fix adds a second loop after the normal signature check that validates the extra variadic arguments against the last signature entry's type constraints.

_type_check only iterates over range(len(signature)). For variadic
functions like merge() where the signature has a single entry with
variadic=True, only the first argument is type-checked. Extra arguments
bypass validation entirely, causing raw Python exceptions (ValueError,
TypeError) instead of JMESPathTypeError.

For example: merge(`{"a":1}`, `"not_a_dict"`) raises ValueError
('dictionary update sequence element #0 has length 1') instead of
JMESPathTypeError.

Fix: after the normal loop, check additional variadic arguments against
the last signature entry's type constraints.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant