Whole file

jmespath/jmespath.py

The author described this change as Fix invalid-type error messages. It counts as a record because the check below fails on the code as it stood at 572635570 and passes on f23b1965b, with nothing else changed between the two runs.

Fix saved2015-04-08
Sharing licenceMIT · LICENSE
Change size+5 3

What the code was meant to do, written into the code itself as a save note

Fix invalid-type error messages

The change

317317 # that validates that type, which requires that remaining array
318318 # elements resolve to the same type as the first element.
319319 required_type = self._convert_to_jmespath_type(
320- self.interpreter.visit(expref.expression, array[0]))
320+ type(self.interpreter.visit(expref.expression, array[0])).__name__)
321321 if required_type not in ['number', 'string']:
322322 raise exceptions.JMESPathTypeError(
323323 'sort_by', array[0], required_type, ['string', 'number'])
345345
346346 def keyfunc(x):
347347 result = interpreter.visit(expr_node, x)
348- jmespath_type = self._convert_to_jmespath_type(result)
348+ actual_typename = type(result).__name__
349+ jmespath_type = self._convert_to_jmespath_type(actual_typename)
350+ # allowed_types is in term of jmespath types, not python types.
349351 if jmespath_type not in allowed_types:
350352 raise exceptions.JMESPathTypeError(
351353 function_name, result, jmespath_type, allowed_types)
353355 return keyfunc
354356
355357 def _convert_to_jmespath_type(self, pyobject):
356- return TYPES_MAP.get(type(pyobject).__name__, 'unknown')
358+ return TYPES_MAP.get(pyobject, 'unknown')
357359

The check that tells the two apart

failpass·tests/test_functions.py::TestFunctions::test_type_error_messages

Check file tests/test_functions.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it57263557099df8e8cf83368448936c147aebd3c7
Broken version dated2015-03-25
Modulejmespath.functions
Units changedRuntimeFunctions
Fingerprintcfd49b2675e13ebf
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in jmespath/jmespath.py