From 8b9a10aa0f17523ea1277845dc422bc7851efc5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Wed, 25 Dec 2024 12:12:42 +0100 Subject: [PATCH] maybe `itertools.chain` is flaky? --- Lib/glob.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Lib/glob.py b/Lib/glob.py index 690ab1b8b9fb1d..45b27354ba5039 100644 --- a/Lib/glob.py +++ b/Lib/glob.py @@ -5,7 +5,6 @@ import re import fnmatch import functools -import itertools import operator import stat import sys @@ -52,13 +51,10 @@ def iglob(pathname, *, root_dir=None, dir_fd=None, recursive=False, it = _iglob(pathname, root_dir, dir_fd, recursive, False, include_hidden=include_hidden) if not pathname or recursive and _isrecursive(pathname[:2]): - try: - s = next(it) # skip empty string - if s: - it = itertools.chain((s,), it) - except StopIteration: - pass - return it + peek = next(it, sentinel := object()) + if peek and peek is not sentinel: + yield peek + yield from it def _iglob(pathname, root_dir, dir_fd, recursive, dironly, include_hidden=False):