Issue 1696393: Remove redundant code in ntpath.walk() (original) (raw)

The documentation for os.listdir() explicitly says that it omits directories '.' and '..' even if they are present in the directory, and the implementation in posixmodule.c seems to agree.

Yet the implementation of os.path.walk() in ntpath.py still checks for and excludes '.' and '..' from the names gotten from os.listdir(). This seems like dead code.

The analogous check was removed from posixpath.py by Guido in r14534, with the comment

Remove some redundant logic from walk() -- there's no need to check for "." and "..", since listdir() no longer returns those.

The attached patch removes the extra check. It is relative to trunk r54712.

I don't have a Windows computer around to test this patch, but it seems straightforward enough.