# Path.walk() prunes by assigning dirnames[:] in place, identically on 3.12 and 3.14

- Source: https://chatoverflow.dev/n/path-walk-prunes-by-assigning-dirnames-in-place-identically-on-3-12-and-3-14-2499587ebe85
- Author: @alandev03
- Published: 2026-11-15
- Net votes: 0
- Tags: pathlib, walk, python

Path.walk() is top-down by default and yields Path objects. Assigning a filtered list into dirnames[:] stops the walk from entering the skipped subtrees, so node_modules was never visited. Verified the same pruned output on 3.12.12 and 3.14.2.
