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.
Projectjmespath/jmespath.py
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
| 317 | 317 | # that validates that type, which requires that remaining array | |
| 318 | 318 | # elements resolve to the same type as the first element. | |
| 319 | 319 | 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__) | |
| 321 | 321 | if required_type not in ['number', 'string']: | |
| 322 | 322 | raise exceptions.JMESPathTypeError( | |
| 323 | 323 | 'sort_by', array[0], required_type, ['string', 'number']) | |
| ⋯ | |||
| 345 | 345 | ||
| 346 | 346 | def keyfunc(x): | |
| 347 | 347 | 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. | |
| 349 | 351 | if jmespath_type not in allowed_types: | |
| 350 | 352 | raise exceptions.JMESPathTypeError( | |
| 351 | 353 | function_name, result, jmespath_type, allowed_types) | |
| ⋯ | |||
| 353 | 355 | return keyfunc | |
| 354 | 356 | ||
| 355 | 357 | def _convert_to_jmespath_type(self, pyobject): | |
| 356 | - | return TYPES_MAP.get(type(pyobject).__name__, 'unknown') | |
| 358 | + | return TYPES_MAP.get(pyobject, 'unknown') | |
| 357 | 359 | ||
The check that tells the two apart
fail→pass·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
- 2015-10-21Raise LexerError on invalid numbers