@@ -322,7 +322,7 @@ def set(
322322 for (i , segment ) in enumerate (segments [:- 1 ]):
323323
324324 # If segment is non-int but supposed to be a sequence index
325- if not isinstance (segment , int ) and segment . isdigit () and isinstance (current , Sequence ):
325+ if isinstance (segment , str ) and isinstance (current , Sequence ) and segment . isdigit ( ):
326326 segment = int (segment )
327327
328328 try :
@@ -341,10 +341,16 @@ def set(
341341 if i != length - 1 and leaf (current ):
342342 raise PathNotFound (f"Path: { segments } [{ i } ]" )
343343
344- if isinstance (segments [- 1 ], int ):
345- extend (current , segments [- 1 ])
344+ last_segment = segments [- 1 ]
346345
347- current [segments [- 1 ]] = value
346+ # Resolve ambiguity of last segment
347+ if isinstance (last_segment , str ) and isinstance (current , Sequence ) and last_segment .isdigit ():
348+ last_segment = int (last_segment )
349+
350+ if isinstance (last_segment , int ):
351+ extend (current , last_segment )
352+
353+ current [last_segment ] = value
348354
349355 return obj
350356
@@ -393,9 +399,11 @@ def view(obj, glob):
393399
394400 view(obj, glob) -> obj'
395401 """
402+
396403 def f (obj , pair , result ):
397404 (segments , value ) = pair
398405 if match (segments , glob ):
399406 if not has (result , segments ):
400407 set (result , segments , deepcopy (value ), hints = types (obj , segments ))
408+
401409 return fold (obj , f , type (obj )())
0 commit comments