[Python-checkins] cpython: Issue #23605: os.walk() doesn't need to call entry.is_symlink() if followlinks

victor.stinner python-checkins at python.org
Thu Mar 12 09:13:03 CET 2015


https://hg.python.org/cpython/rev/1a972140ab62
changeset:   94950:1a972140ab62
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Mar 12 09:12:48 2015 +0100
summary:
  Issue #23605: os.walk() doesn't need to call entry.is_symlink() if followlinks
is True

files:
  Lib/os.py |  5 +++--
  1 files changed, 3 insertions(+), 2 deletions(-)


diff --git a/Lib/os.py b/Lib/os.py
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -374,7 +374,10 @@
 
             if is_dir:
                 dirs.append(entry.name)
+            else:
+                nondirs.append(entry.name)
 
+            if is_dir and not followlinks:
                 try:
                     if entry.is_symlink():
                         symlinks.add(entry.name)
@@ -383,8 +386,6 @@
                     # entry is not a symbolik link, same behaviour than
                     # os.path.islink().
                     pass
-            else:
-                nondirs.append(entry.name)
     except OSError as error:
         # scandir() or iterating into scandir() iterator raised an OSError
         if onerror is not None:

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list