summaryrefslogtreecommitdiffstats
path: root/Lib/os.py
diff options
context:
space:
mode:
authorStanislav Zmiev <zertarx@gmail.com>2023-01-02 21:41:19 (GMT)
committerGitHub <noreply@github.com>2023-01-02 21:41:19 (GMT)
commit73097d91a64620ae7f620705864b84234d85cc82 (patch)
tree91921b9fa8ab6f2479cff36c6c1c0b8fb818cce6 /Lib/os.py
parentd7e7f79ca7c2029e46a06d21a7a5abea631b5d13 (diff)
downloadcpython-73097d91a64620ae7f620705864b84234d85cc82.zip
cpython-73097d91a64620ae7f620705864b84234d85cc82.tar.gz
cpython-73097d91a64620ae7f620705864b84234d85cc82.tar.bz2
gh-89727: Improve os.walk complexity (#100671)
Diffstat (limited to 'Lib/os.py')
-rw-r--r--Lib/os.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 73a5442..598c9e5 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -341,11 +341,11 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
"""
sys.audit("os.walk", top, topdown, onerror, followlinks)
- stack = [(False, fspath(top))]
+ stack = [fspath(top)]
islink, join = path.islink, path.join
while stack:
- must_yield, top = stack.pop()
- if must_yield:
+ top = stack.pop()
+ if isinstance(top, tuple):
yield top
continue
@@ -422,13 +422,13 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
# the caller can replace the directory entry during the "yield"
# above.
if followlinks or not islink(new_path):
- stack.append((False, new_path))
+ stack.append(new_path)
else:
# Yield after sub-directory traversal if going bottom up
- stack.append((True, (top, dirs, nondirs)))
+ stack.append((top, dirs, nondirs))
# Traverse into sub-directories
for new_path in reversed(walk_dirs):
- stack.append((False, new_path))
+ stack.append(new_path)
__all__.append("walk")