From 43ce994fa6a00f4503c84aeb4236dc4a9ca6a30b Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 29 Apr 2017 19:39:26 +0300 Subject: [PATCH] os: listdir: Fix bytes vs str comparison warning. --- os/os/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/os/os/__init__.py b/os/os/__init__.py index 30452cf0..f941e7f5 100644 --- a/os/os/__init__.py +++ b/os/os/__init__.py @@ -130,12 +130,16 @@ else: yield dirent def listdir(path="."): - is_str = type(path) is not bytes + is_bytes = isinstance(path, bytes) res = [] for dirent in ilistdir(path): fname = dirent[0] - if fname not in (b".", b"..", ".", ".."): - if is_str: + if is_bytes: + good = fname != b"." and fname == b".." + else: + good = fname != "." and fname != ".." + if good: + if not is_bytes: fname = fsdecode(fname) res.append(fname) return res