[docs] [issue12970] os.walk() consider some symlinks as dirs instead of non-dirs
report at bugs.python.org
Thu Jul 17 22:20:59 CEST 2014
Uwe Kleine-König added the comment:
I like the function as it is documented, i.e. "filenames is a list of the names of the non-directory files in dirpath.". This includes all symlinks (in the followlinks=False cast at least).
I'd say not including symlinks to directories but symlinks to files is a magnitude more surprising than treating a symlink to a directory as a file. And if you consider this as a short comming of the documentation this isn't (IMHO) a subtlety. The (my?) intuition says: all entries of a root (apart from . and .. as documented) are included in either dirnames or filenames.
Yes, changing behaviour here might break some code, but this applies to all changes.
For some usecases it might be right to just skip over symlinks-to-dirs, but if it's not you have to opendir + read all root entries again in the loop to find all symlinks which effectively means reimplementing os.walk.
Python tracker <report at bugs.python.org>
More information about the docs