@@ -81,7 +81,7 @@ def walk(obj, location=()):
8181 yield found
8282
8383
84- def get (obj , segments ):
84+ def get (obj , segments : Path ):
8585 """
8686 Return the value at the path indicated by segments.
8787
@@ -92,6 +92,9 @@ def get(obj, segments):
9292 if leaf (current ):
9393 raise PathNotFound (f"Path: { segments } [{ i } ]" )
9494
95+ if isinstance (current , Sequence ) and isinstance (segment , (str , bytes )) and segment .isdigit ():
96+ segment = int (segment )
97+
9598 current = current [segment ]
9699 return current
97100
@@ -339,7 +342,7 @@ def set(
339342 for (i , segment ) in enumerate (segments [:- 1 ]):
340343
341344 # If segment is non-int but supposed to be a sequence index
342- if isinstance (segment , str ) and isinstance (current , Sequence ) and segment .isdigit ():
345+ if isinstance (segment , ( str , bytes ) ) and isinstance (current , Sequence ) and segment .isdigit ():
343346 segment = int (segment )
344347
345348 try :
@@ -361,7 +364,7 @@ def set(
361364 last_segment = segments [- 1 ]
362365
363366 # Resolve ambiguity of last segment
364- if isinstance (last_segment , str ) and isinstance (current , Sequence ) and last_segment .isdigit ():
367+ if isinstance (last_segment , ( str , bytes ) ) and isinstance (current , Sequence ) and last_segment .isdigit ():
365368 last_segment = int (last_segment )
366369
367370 if isinstance (last_segment , int ):
0 commit comments