You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prior to the fix for #89727, it was possible influence which subdirectories were visited by os.walk()even after the walk had descended into siblings of those subdirectories. Such "late" modifications no longer have any effect.
I think you changed os.walk's behavior. The recursive one supported late modifications of subdirs lists, due to being lazier. The iterative one doesn't (if I'm not mistaken... I can't test).
With topdown, you can modify a directory's subdirs, for example remove one and it won't be visited. Usually you'd do that while your walk is on that parent directory. But with the recursive one, it was possible to do it later. With the iterative one, I don't think that works anymore.
Here's a demo where I remove the second subdir after having walked onto the first:
importos# Create demo dir with three subdirsos.makedirs('demo/a')
os.makedirs('demo/b')
os.makedirs('demo/c')
# Walk onto "demo"walk=os.walk('demo')
demo=next(walk)
print(demo)
# Walk onto first subdirfirst=next(walk)
print(first)
# Remove the second subdirdeldemo[1][1]
# Walk onto the remaining subdirsforxinwalk:
print(x)
Output (Try it online!), note that the second subdir wasn't walked:
The iteration of dirs and the walking of the subdirs are intertwined. After walking a subdir, the paused iteration of dirs resumes. That allows the late modifications of dirs to have an effect.
This eagerly puts all subdirs onto the stack, before they're getting walked, and then dirs is never used again. So modifying dirs during the subdirs walking doesn't have an effect anymore.
The text was updated successfully, but these errors were encountered:
Prior to the fix for #89727, it was possible influence which subdirectories were visited by
os.walk()
even after the walk had descended into siblings of those subdirectories. Such "late" modifications no longer have any effect.This was reported by @pochmann:
The text was updated successfully, but these errors were encountered: