--- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -8,7 +8,7 @@ import sys from collections import Sequence from contextlib import contextmanager -from errno import EINVAL, ENOENT +from errno import EINVAL, ENOENT, ENOTDIR from operator import attrgetter from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO from urllib.parse import quote_from_bytes as urlquote_from_bytes @@ -1238,7 +1238,7 @@ try: self.stat() except OSError as e: - if e.errno != ENOENT: + if e.errno != ENOENT and e.errno != ENOTDIR: raise return False return True @@ -1250,7 +1250,7 @@ try: return S_ISDIR(self.stat().st_mode) except OSError as e: - if e.errno != ENOENT: + if e.errno != ENOENT and e.errno != ENOTDIR: raise # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) @@ -1264,7 +1264,7 @@ try: return S_ISREG(self.stat().st_mode) except OSError as e: - if e.errno != ENOENT: + if e.errno != ENOENT and e.errno != ENOTDIR: raise # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) @@ -1277,7 +1277,7 @@ try: return S_ISLNK(self.lstat().st_mode) except OSError as e: - if e.errno != ENOENT: + if e.errno != ENOENT and e.errno != ENOTDIR: raise # Path doesn't exist return False @@ -1289,7 +1289,7 @@ try: return S_ISBLK(self.stat().st_mode) except OSError as e: - if e.errno != ENOENT: + if e.errno != ENOENT and e.errno != ENOTDIR: raise # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) @@ -1302,7 +1302,7 @@ try: return S_ISCHR(self.stat().st_mode) except OSError as e: - if e.errno != ENOENT: + if e.errno != ENOENT and e.errno != ENOTDIR: raise # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) @@ -1315,7 +1315,7 @@ try: return S_ISFIFO(self.stat().st_mode) except OSError as e: - if e.errno != ENOENT: + if e.errno != ENOENT and e.errno != ENOTDIR: raise # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/) @@ -1328,7 +1328,7 @@ try: return S_ISSOCK(self.stat().st_mode) except OSError as e: - if e.errno != ENOENT: + if e.errno != ENOENT and e.errno != ENOTDIR: raise # Path doesn't exist or is a broken symlink # (see https://bitbucket.org/pitrou/pathlib/issue/12/)