Skip to content

Commit 43ce994

Browse files
committed
os: listdir: Fix bytes vs str comparison warning.
1 parent 94f1584 commit 43ce994

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

os/os/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,16 @@ def ilistdir(path="."):
130130
yield dirent
131131

132132
def listdir(path="."):
133-
is_str = type(path) is not bytes
133+
is_bytes = isinstance(path, bytes)
134134
res = []
135135
for dirent in ilistdir(path):
136136
fname = dirent[0]
137-
if fname not in (b".", b"..", ".", ".."):
138-
if is_str:
137+
if is_bytes:
138+
good = fname != b"." and fname == b".."
139+
else:
140+
good = fname != "." and fname != ".."
141+
if good:
142+
if not is_bytes:
139143
fname = fsdecode(fname)
140144
res.append(fname)
141145
return res

0 commit comments

Comments
 (0)