mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #22759: Query methods on pathlib.Path() (exists(), is_dir(), etc.) now return False when the underlying stat call raises NotADirectoryError.
This commit is contained in:
parent
35903c809f
commit
2b2852b1b4
3 changed files with 22 additions and 9 deletions
|
@ -8,7 +8,7 @@ import re
|
|||
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
|
||||
|
@ -1187,7 +1187,7 @@ class Path(PurePath):
|
|||
try:
|
||||
self.stat()
|
||||
except OSError as e:
|
||||
if e.errno != ENOENT:
|
||||
if e.errno not in (ENOENT, ENOTDIR):
|
||||
raise
|
||||
return False
|
||||
return True
|
||||
|
@ -1199,7 +1199,7 @@ class Path(PurePath):
|
|||
try:
|
||||
return S_ISDIR(self.stat().st_mode)
|
||||
except OSError as e:
|
||||
if e.errno != ENOENT:
|
||||
if e.errno not in (ENOENT, ENOTDIR):
|
||||
raise
|
||||
# Path doesn't exist or is a broken symlink
|
||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||
|
@ -1213,7 +1213,7 @@ class Path(PurePath):
|
|||
try:
|
||||
return S_ISREG(self.stat().st_mode)
|
||||
except OSError as e:
|
||||
if e.errno != ENOENT:
|
||||
if e.errno not in (ENOENT, ENOTDIR):
|
||||
raise
|
||||
# Path doesn't exist or is a broken symlink
|
||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||
|
@ -1226,7 +1226,7 @@ class Path(PurePath):
|
|||
try:
|
||||
return S_ISLNK(self.lstat().st_mode)
|
||||
except OSError as e:
|
||||
if e.errno != ENOENT:
|
||||
if e.errno not in (ENOENT, ENOTDIR):
|
||||
raise
|
||||
# Path doesn't exist
|
||||
return False
|
||||
|
@ -1238,7 +1238,7 @@ class Path(PurePath):
|
|||
try:
|
||||
return S_ISBLK(self.stat().st_mode)
|
||||
except OSError as e:
|
||||
if e.errno != ENOENT:
|
||||
if e.errno not in (ENOENT, ENOTDIR):
|
||||
raise
|
||||
# Path doesn't exist or is a broken symlink
|
||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||
|
@ -1251,7 +1251,7 @@ class Path(PurePath):
|
|||
try:
|
||||
return S_ISCHR(self.stat().st_mode)
|
||||
except OSError as e:
|
||||
if e.errno != ENOENT:
|
||||
if e.errno not in (ENOENT, ENOTDIR):
|
||||
raise
|
||||
# Path doesn't exist or is a broken symlink
|
||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||
|
@ -1264,7 +1264,7 @@ class Path(PurePath):
|
|||
try:
|
||||
return S_ISFIFO(self.stat().st_mode)
|
||||
except OSError as e:
|
||||
if e.errno != ENOENT:
|
||||
if e.errno not in (ENOENT, ENOTDIR):
|
||||
raise
|
||||
# Path doesn't exist or is a broken symlink
|
||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||
|
@ -1277,7 +1277,7 @@ class Path(PurePath):
|
|||
try:
|
||||
return S_ISSOCK(self.stat().st_mode)
|
||||
except OSError as e:
|
||||
if e.errno != ENOENT:
|
||||
if e.errno not in (ENOENT, ENOTDIR):
|
||||
raise
|
||||
# Path doesn't exist or is a broken symlink
|
||||
# (see https://bitbucket.org/pitrou/pathlib/issue/12/)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue