From 4dbcee3ece98c7f743bc3bc74b7ae645a8ca40ba Mon Sep 17 00:00:00 2001 From: Kadir Can Ozden <101993364+bysiber@users.noreply.github.com> Date: Fri, 20 Feb 2026 14:46:29 +0300 Subject: [PATCH] Type-check extra arguments to variadic functions _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. --- jmespath/functions.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jmespath/functions.py b/jmespath/functions.py index 627b569..670fb04 100644 --- a/jmespath/functions.py +++ b/jmespath/functions.py @@ -96,6 +96,12 @@ def _type_check(self, actual, signature, function_name): if allowed_types: self._type_check_single(actual[i], allowed_types, function_name) + if signature and signature[-1].get('variadic'): + allowed_types = signature[-1]['types'] + if allowed_types: + for i in range(len(signature), len(actual)): + self._type_check_single(actual[i], allowed_types, + function_name) def _type_check_single(self, current, types, function_name): # Type checking involves checking the top level type,