File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed
Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -81,19 +81,18 @@ def normalize_large_integers_to_strings(
8181 Returns:
8282 A normalized value.
8383 """
84- if isinstance (value , dict ):
85- return {
86- k : normalize_large_integers_to_strings (v , max_safe_digits )
87- for k , v in value .items ()
88- }
89- if isinstance (value , list | tuple ):
90- return [
91- normalize_large_integers_to_strings (item , max_safe_digits )
92- for item in value
93- ]
94- if isinstance (value , int ) and abs (value ) > (10 ** max_safe_digits - 1 ):
95- return str (value )
96- return value
84+ max_safe_int = 10 ** max_safe_digits - 1
85+
86+ def _normalize (item : Any ) -> Any :
87+ if isinstance (item , int ) and abs (item ) > max_safe_int :
88+ return str (item )
89+ if isinstance (item , dict ):
90+ return {k : _normalize (v ) for k , v in item .items ()}
91+ if isinstance (item , list | tuple ):
92+ return [_normalize (i ) for i in item ]
93+ return item
94+
95+ return _normalize (value )
9796
9897
9998def parse_string_integers_in_dict (value : Any , max_safe_digits : int = 15 ) -> Any :
You can’t perform that action at this time.
0 commit comments