@@ -317,7 +317,7 @@ def _func_sort_by(self, array, expref):
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,12 +345,14 @@ def _create_key_func(self, expr_node, allowed_types, function_name):
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 )
352
354
return result
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' )
0 commit comments