Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Open
Description
There are a couple of minor performance improvements possible inos.walk():
- We don't need to manually pump the
os.scandiriterator, given we handle exceptions fromnext()like exceptions fromscandir()itself, i.e. by ignoring the problematic directory and moving on. We can use aforloop like filthy casuals. In bottom-up mode, we can handle exceptions fromentry.is_symlink()in the same block as those fromentry.is_dir(), which avoids a few temporary variables.- In top-down mode, we can call
os.path.join()once on a parent directory rather than for each child path.
Linked PRs
- GH-119169: Speed up
os.walk(topdown=False)#119186 - GH-119169: Skip reversing sibling directories in
os.[f]walk(topdown=False)#119473 - GH-119169: Implement
pathlib.Path.walk()usingos.walk()#119573 - [3.13] GH-119169: Implement
pathlib.Path.walk()usingos.walk()(GH-119573) #119750 - GH-119169: Slightly speed up
os.walk(topdown=True)#121431 - GH-119169: Simplify
os.fwalk()exception handling #121432 - GH-119169: Speed up
os.fwalk(topdown=False)#121433 - GH-119169: Simplify
os.walk()exception handling #121435