From f1eb06c6899ccbf427873e69ca7c98f6371f4f4b Mon Sep 17 00:00:00 2001 From: barneygale Date: Wed, 24 Apr 2024 20:31:01 +0100 Subject: [PATCH 1/6] GH-101357: Suppress `OSError` from `pathlib.Path.exists()` and `is_*()` Suppress all `OSError` exceptions from `pathlib.Path.exists()` and `is_*()` rather than a selection of more common errors as we do presently. Also adjust the implementations to call `os.path.exists()` etc, which are much faster on Windows thanks to GH-101196. --- Doc/library/pathlib.rst | 32 ++++++++------ Lib/glob.py | 10 ++--- Lib/pathlib/__init__.py | 34 +++++++++++++++ Lib/pathlib/_abc.py | 93 +++++------------------------------------ 4 files changed, 66 insertions(+), 103 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 2e18e41869376e..dd3bf4f72a5ffb 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -874,7 +874,7 @@ Methods ^^^^^^^ Concrete paths provide the following methods in addition to pure paths -methods. Many of these methods can raise an :exc:`OSError` if a system +methods. Some of these methods can raise an :exc:`OSError` if a system call fails (for example because the path doesn't exist). .. versionchanged:: 3.8 @@ -886,6 +886,12 @@ call fails (for example because the path doesn't exist). instead of raising an exception for paths that contain characters unrepresentable at the OS level. +.. versionchanged:: 3.14 + + The methods given above now return ``False`` instead of raising an + :exc:`OSError` exception from the operating system. In previous versions, + some kinds of :exc:`OSError` exception are raised, and others suppressed. + .. classmethod:: Path.cwd() @@ -1071,8 +1077,8 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a directory, ``False`` if it points to another kind of file. - ``False`` is also returned if the path doesn't exist or is a broken symlink; - other errors (such as permission errors) are propagated. + ``False`` is also returned if the path doesn't exist, or is a broken + symlink, or is inaccessible for any other reason. This method normally follows symlinks; to exclude symlinks to directories, add the argument ``follow_symlinks=False``. @@ -1086,8 +1092,8 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a regular file, ``False`` if it points to another kind of file. - ``False`` is also returned if the path doesn't exist or is a broken symlink; - other errors (such as permission errors) are propagated. + ``False`` is also returned if the path doesn't exist, or is a broken + symlink, or is inaccessible for any other reason. This method normally follows symlinks; to exclude symlinks, add the argument ``follow_symlinks=False``. @@ -1125,8 +1131,8 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a symbolic link, ``False`` otherwise. - ``False`` is also returned if the path doesn't exist; other errors (such - as permission errors) are propagated. + ``False`` is also returned if the path doesn't exist or is inaccessible for + any other reason. .. method:: Path.is_socket() @@ -1143,8 +1149,8 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a FIFO (or a symbolic link pointing to a FIFO), ``False`` if it points to another kind of file. - ``False`` is also returned if the path doesn't exist or is a broken symlink; - other errors (such as permission errors) are propagated. + ``False`` is also returned if the path doesn't exist, or is a broken + symlink, or is inaccessible for any other reason. .. method:: Path.is_block_device() @@ -1152,8 +1158,8 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a block device (or a symbolic link pointing to a block device), ``False`` if it points to another kind of file. - ``False`` is also returned if the path doesn't exist or is a broken symlink; - other errors (such as permission errors) are propagated. + ``False`` is also returned if the path doesn't exist, or is a broken + symlink, or is inaccessible for any other reason. .. method:: Path.is_char_device() @@ -1161,8 +1167,8 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a character device (or a symbolic link pointing to a character device), ``False`` if it points to another kind of file. - ``False`` is also returned if the path doesn't exist or is a broken symlink; - other errors (such as permission errors) are propagated. + ``False`` is also returned if the path doesn't exist, or is a broken + symlink, or is inaccessible for any other reason. .. method:: Path.iterdir() diff --git a/Lib/glob.py b/Lib/glob.py index 72cf22299763f0..4843b22e7e2695 100644 --- a/Lib/glob.py +++ b/Lib/glob.py @@ -339,7 +339,7 @@ def __init__(self, sep, case_sensitive, case_pedantic=False, recursive=False): # Low-level methods - lstat = staticmethod(os.lstat) + lexists = staticmethod(os.path.lexists) scandir = staticmethod(os.scandir) parse_entry = operator.attrgetter('path') concat_path = operator.add @@ -512,12 +512,8 @@ def select_exists(self, path, exists=False): # Optimization: this path is already known to exist, e.g. because # it was returned from os.scandir(), so we skip calling lstat(). yield path - else: - try: - self.lstat(path) - yield path - except OSError: - pass + elif self.lexists(path): + yield path @classmethod def walk(cls, root, top_down, on_error, follow_symlinks): diff --git a/Lib/pathlib/__init__.py b/Lib/pathlib/__init__.py index f03f317ef6c16a..07681c29a3c70e 100644 --- a/Lib/pathlib/__init__.py +++ b/Lib/pathlib/__init__.py @@ -525,12 +525,46 @@ def stat(self, *, follow_symlinks=True): """ return os.stat(self, follow_symlinks=follow_symlinks) + def exists(self, *, follow_symlinks=True): + """ + Whether this path exists. + + This method normally follows symlinks; to check whether a symlink exists, + add the argument follow_symlinks=False. + """ + if follow_symlinks: + return os.path.exists(self) + return os.path.lexists(self) + + def is_dir(self, *, follow_symlinks=True): + """ + Whether this path is a directory. + """ + if follow_symlinks: + return os.path.isdir(self) + return _abc.PathBase.is_dir(self, follow_symlinks=follow_symlinks) + + def is_file(self, *, follow_symlinks=True): + """ + Whether this path is a regular file (also True for symlinks pointing + to regular files). + """ + if follow_symlinks: + return os.path.isfile(self) + return _abc.PathBase.is_file(self, follow_symlinks=follow_symlinks) + def is_mount(self): """ Check if this path is a mount point """ return os.path.ismount(self) + def is_symlink(self): + """ + Whether this path is a symbolic link. + """ + return os.path.islink(self) + def is_junction(self): """ Whether this path is a junction. diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py index 05698d5de24afb..8d97fad491c79a 100644 --- a/Lib/pathlib/_abc.py +++ b/Lib/pathlib/_abc.py @@ -14,29 +14,9 @@ import functools import glob import operator -from errno import ENOENT, ENOTDIR, EBADF, ELOOP, EINVAL +from errno import ENOTDIR, ELOOP from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO -# -# Internals -# - -_WINERROR_NOT_READY = 21 # drive exists but is not accessible -_WINERROR_INVALID_NAME = 123 # fix for bpo-35306 -_WINERROR_CANT_RESOLVE_FILENAME = 1921 # broken symlink pointing to itself - -# EBADF - guard against macOS `stat` throwing EBADF -_IGNORED_ERRNOS = (ENOENT, ENOTDIR, EBADF, ELOOP) - -_IGNORED_WINERRORS = ( - _WINERROR_NOT_READY, - _WINERROR_INVALID_NAME, - _WINERROR_CANT_RESOLVE_FILENAME) - -def _ignore_error(exception): - return (getattr(exception, 'errno', None) in _IGNORED_ERRNOS or - getattr(exception, 'winerror', None) in _IGNORED_WINERRORS) - @functools.cache def _is_case_sensitive(parser): @@ -44,7 +24,7 @@ def _is_case_sensitive(parser): class Globber(glob._Globber): - lstat = operator.methodcaller('lstat') + lexists = operator.methodcaller('exists', follow_symlinks=False) add_slash = operator.methodcaller('joinpath', '') @staticmethod @@ -472,12 +452,7 @@ def exists(self, *, follow_symlinks=True): """ try: self.stat(follow_symlinks=follow_symlinks) - except OSError as e: - if not _ignore_error(e): - raise - return False - except ValueError: - # Non-encodable path + except (OSError, ValueError): return False return True @@ -487,14 +462,7 @@ def is_dir(self, *, follow_symlinks=True): """ try: return S_ISDIR(self.stat(follow_symlinks=follow_symlinks).st_mode) - except OSError as e: - if not _ignore_error(e): - raise - # Path doesn't exist or is a broken symlink - # (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ ) - return False - except ValueError: - # Non-encodable path + except (OSError, ValueError): return False def is_file(self, *, follow_symlinks=True): @@ -504,14 +472,7 @@ def is_file(self, *, follow_symlinks=True): """ try: return S_ISREG(self.stat(follow_symlinks=follow_symlinks).st_mode) - except OSError as e: - if not _ignore_error(e): - raise - # Path doesn't exist or is a broken symlink - # (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ ) - return False - except ValueError: - # Non-encodable path + except (OSError, ValueError): return False def is_mount(self): @@ -540,13 +501,7 @@ def is_symlink(self): """ try: return S_ISLNK(self.lstat().st_mode) - except OSError as e: - if not _ignore_error(e): - raise - # Path doesn't exist - return False - except ValueError: - # Non-encodable path + except (OSError, ValueError): return False def is_junction(self): @@ -564,14 +519,7 @@ def is_block_device(self): """ try: return S_ISBLK(self.stat().st_mode) - except OSError as e: - if not _ignore_error(e): - raise - # Path doesn't exist or is a broken symlink - # (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ ) - return False - except ValueError: - # Non-encodable path + except (OSError, ValueError): return False def is_char_device(self): @@ -580,14 +528,7 @@ def is_char_device(self): """ try: return S_ISCHR(self.stat().st_mode) - except OSError as e: - if not _ignore_error(e): - raise - # Path doesn't exist or is a broken symlink - # (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ ) - return False - except ValueError: - # Non-encodable path + except (OSError, ValueError): return False def is_fifo(self): @@ -596,14 +537,7 @@ def is_fifo(self): """ try: return S_ISFIFO(self.stat().st_mode) - except OSError as e: - if not _ignore_error(e): - raise - # Path doesn't exist or is a broken symlink - # (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ ) - return False - except ValueError: - # Non-encodable path + except (OSError, ValueError): return False def is_socket(self): @@ -612,14 +546,7 @@ def is_socket(self): """ try: return S_ISSOCK(self.stat().st_mode) - except OSError as e: - if not _ignore_error(e): - raise - # Path doesn't exist or is a broken symlink - # (see http://web.archive.org/web/20200623061726/https://bitbucket.org/pitrou/pathlib/issues/12/ ) - return False - except ValueError: - # Non-encodable path + except (OSError, ValueError): return False def samefile(self, other_path): From dbf9626268a47e5d2f3946bd66d99ffc29b76cab Mon Sep 17 00:00:00 2001 From: barneygale Date: Wed, 8 May 2024 19:49:38 +0100 Subject: [PATCH 2/6] Add news --- .../next/Library/2024-05-08-19-47-34.gh-issue-101357.e4R_9x.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-05-08-19-47-34.gh-issue-101357.e4R_9x.rst diff --git a/Misc/NEWS.d/next/Library/2024-05-08-19-47-34.gh-issue-101357.e4R_9x.rst b/Misc/NEWS.d/next/Library/2024-05-08-19-47-34.gh-issue-101357.e4R_9x.rst new file mode 100644 index 00000000000000..6b6d8ae69b3974 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-05-08-19-47-34.gh-issue-101357.e4R_9x.rst @@ -0,0 +1,2 @@ +Suppress all :exc:`OSError` exceptions from :meth:`pathlib.Path.exists` and +``is_*()`` methods, rather than a selection of more common errors. From 1842b6d34c80f0cc487fc0bfbb8a65a7d77839fb Mon Sep 17 00:00:00 2001 From: barneygale Date: Fri, 10 May 2024 19:57:20 +0100 Subject: [PATCH 3/6] Address review feedback --- Doc/library/pathlib.rst | 5 ++++- .../Library/2024-05-08-19-47-34.gh-issue-101357.e4R_9x.rst | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index dd3bf4f72a5ffb..6f12171387e5b1 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -888,9 +888,12 @@ call fails (for example because the path doesn't exist). .. versionchanged:: 3.14 - The methods given above now return ``False`` instead of raising an + The methods given above now return ``False`` instead of raising any :exc:`OSError` exception from the operating system. In previous versions, some kinds of :exc:`OSError` exception are raised, and others suppressed. + The new behaviour is consistent with :func:`os.path.exists`, + :func:`os.path.isdir`, etc. Use :meth:`~Path.stat` to retrieve the file + status without suppressing exceptions. .. classmethod:: Path.cwd() diff --git a/Misc/NEWS.d/next/Library/2024-05-08-19-47-34.gh-issue-101357.e4R_9x.rst b/Misc/NEWS.d/next/Library/2024-05-08-19-47-34.gh-issue-101357.e4R_9x.rst index 6b6d8ae69b3974..9fad7a416fcc24 100644 --- a/Misc/NEWS.d/next/Library/2024-05-08-19-47-34.gh-issue-101357.e4R_9x.rst +++ b/Misc/NEWS.d/next/Library/2024-05-08-19-47-34.gh-issue-101357.e4R_9x.rst @@ -1,2 +1,5 @@ Suppress all :exc:`OSError` exceptions from :meth:`pathlib.Path.exists` and -``is_*()`` methods, rather than a selection of more common errors. +``is_*()`` methods, rather than a selection of more common errors. The new +behaviour is consistent with :func:`os.path.exists`, :func:`os.path.isdir`, +etc. Use :meth:`Path.stat` to retrieve the file status without suppressing +exceptions. From fad9af4cfab58f59b24fc69762ad6f0d250a5efd Mon Sep 17 00:00:00 2001 From: barneygale Date: Mon, 13 May 2024 18:45:54 +0100 Subject: [PATCH 4/6] Address review feedback? --- Doc/library/pathlib.rst | 55 ++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 6f12171387e5b1..89f39228086afd 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -1077,11 +1077,9 @@ call fails (for example because the path doesn't exist). .. method:: Path.is_dir(*, follow_symlinks=True) - Return ``True`` if the path points to a directory, ``False`` if it points - to another kind of file. - - ``False`` is also returned if the path doesn't exist, or is a broken - symlink, or is inaccessible for any other reason. + Return ``True`` if the path points to an accessible directory, ``False`` + otherwise. Use :meth:`Path.exists` to test if a path is accessible without + checking its type. This method normally follows symlinks; to exclude symlinks to directories, add the argument ``follow_symlinks=False``. @@ -1092,11 +1090,9 @@ call fails (for example because the path doesn't exist). .. method:: Path.is_file(*, follow_symlinks=True) - Return ``True`` if the path points to a regular file, ``False`` if it - points to another kind of file. - - ``False`` is also returned if the path doesn't exist, or is a broken - symlink, or is inaccessible for any other reason. + Return ``True`` if the path points to an accessible regular file, ``False`` + otherwise. Use :meth:`Path.exists` to test if a path is accessible without + checking its type. This method normally follows symlinks; to exclude symlinks, add the argument ``follow_symlinks=False``. @@ -1132,46 +1128,37 @@ call fails (for example because the path doesn't exist). .. method:: Path.is_symlink() - Return ``True`` if the path points to a symbolic link, ``False`` otherwise. - - ``False`` is also returned if the path doesn't exist or is inaccessible for - any other reason. + Return ``True`` if the path points to an accessible symbolic link, + ``False`` otherwise. Use :meth:`Path.exists` to test if a path is + accessible without checking its type. .. method:: Path.is_socket() - Return ``True`` if the path points to a Unix socket (or a symbolic link - pointing to a Unix socket), ``False`` if it points to another kind of file. - - ``False`` is also returned if the path doesn't exist or is a broken symlink; - other errors (such as permission errors) are propagated. + Return ``True`` if the path points to an accessible Unix socket, ``False`` + otherwise. Use :meth:`Path.exists` to test if a path is accessible without + checking its type. .. method:: Path.is_fifo() - Return ``True`` if the path points to a FIFO (or a symbolic link - pointing to a FIFO), ``False`` if it points to another kind of file. - - ``False`` is also returned if the path doesn't exist, or is a broken - symlink, or is inaccessible for any other reason. + Return ``True`` if the path points to an accessible FIFO, ``False`` + otherwise. Use :meth:`Path.exists` to test if a path is accessible without + checking its type. .. method:: Path.is_block_device() - Return ``True`` if the path points to a block device (or a symbolic link - pointing to a block device), ``False`` if it points to another kind of file. - - ``False`` is also returned if the path doesn't exist, or is a broken - symlink, or is inaccessible for any other reason. + Return ``True`` if the path points to an accessible block device, ``False`` + otherwise. Use :meth:`Path.exists` to test if a path is accessible without + checking its type. .. method:: Path.is_char_device() - Return ``True`` if the path points to a character device (or a symbolic link - pointing to a character device), ``False`` if it points to another kind of file. - - ``False`` is also returned if the path doesn't exist, or is a broken - symlink, or is inaccessible for any other reason. + Return ``True`` if the path points to an accessible character device, + ``False`` otherwise. Use :meth:`Path.exists` to test if a path is + accessible without checking its type. .. method:: Path.iterdir() From a7f83721d97f7b2b6c0efb21929b359c4143ed22 Mon Sep 17 00:00:00 2001 From: barneygale Date: Mon, 13 May 2024 20:43:57 +0100 Subject: [PATCH 5/6] More docs tweaks --- Doc/library/pathlib.rst | 49 +++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index 89f39228086afd..cfb4e0574e0cbb 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -1077,9 +1077,10 @@ call fails (for example because the path doesn't exist). .. method:: Path.is_dir(*, follow_symlinks=True) - Return ``True`` if the path points to an accessible directory, ``False`` - otherwise. Use :meth:`Path.exists` to test if a path is accessible without - checking its type. + Return ``True`` if the path points to a directory. ``False`` will be + returned if the path is invalid, inaccessible or missing, or if it points + to something other than a directory. Use :meth:`Path.exists` to distinguish + between these cases. This method normally follows symlinks; to exclude symlinks to directories, add the argument ``follow_symlinks=False``. @@ -1090,9 +1091,10 @@ call fails (for example because the path doesn't exist). .. method:: Path.is_file(*, follow_symlinks=True) - Return ``True`` if the path points to an accessible regular file, ``False`` - otherwise. Use :meth:`Path.exists` to test if a path is accessible without - checking its type. + Return ``True`` if the path points to a regular file. ``False`` will be + returned if the path is invalid, inaccessible or missing, or if it points + to something other than a regular file. Use :meth:`Path.exists` to + distinguish between these cases. This method normally follows symlinks; to exclude symlinks, add the argument ``follow_symlinks=False``. @@ -1128,37 +1130,42 @@ call fails (for example because the path doesn't exist). .. method:: Path.is_symlink() - Return ``True`` if the path points to an accessible symbolic link, - ``False`` otherwise. Use :meth:`Path.exists` to test if a path is - accessible without checking its type. + Return ``True`` if the path points to a symbolic link, even if that symlink + is broken. ``False`` will be returned if the path is invalid, inaccessible + or missing, or if it points to something other than a symbolic link. Use + :meth:`Path.exists` to distinguish between these cases. .. method:: Path.is_socket() - Return ``True`` if the path points to an accessible Unix socket, ``False`` - otherwise. Use :meth:`Path.exists` to test if a path is accessible without - checking its type. + Return ``True`` if the path points to a Unix socket. ``False`` will be + returned if the path is invalid, inaccessible or missing, or if it points + to something other than a Unix socket. Use :meth:`Path.exists` to + distinguish between these cases. .. method:: Path.is_fifo() - Return ``True`` if the path points to an accessible FIFO, ``False`` - otherwise. Use :meth:`Path.exists` to test if a path is accessible without - checking its type. + Return ``True`` if the path points to a FIFO. ``False`` will be returned if + the path is invalid, inaccessible or missing, or if it points to something + other than a FIFO. Use :meth:`Path.exists` to distinguish between these + cases. .. method:: Path.is_block_device() - Return ``True`` if the path points to an accessible block device, ``False`` - otherwise. Use :meth:`Path.exists` to test if a path is accessible without - checking its type. + Return ``True`` if the path points to a block device. ``False`` will be + returned if the path is invalid, inaccessible or missing, or if it points + to something other than a block device. Use :meth:`Path.exists` to + distinguish between these cases. .. method:: Path.is_char_device() - Return ``True`` if the path points to an accessible character device, - ``False`` otherwise. Use :meth:`Path.exists` to test if a path is - accessible without checking its type. + Return ``True`` if the path points to a character device. ``False`` will be + returned if the path is invalid, inaccessible or missing, or if it points + to something other than a character device. Use :meth:`Path.exists` to + distinguish between these cases. .. method:: Path.iterdir() From 749731fffb5db9d0a3c24e2858a99b7d746529a5 Mon Sep 17 00:00:00 2001 From: barneygale Date: Tue, 14 May 2024 18:30:17 +0100 Subject: [PATCH 6/6] exists() --> stat() --- Doc/library/pathlib.rst | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index cfb4e0574e0cbb..82c18fb0a8495a 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -961,6 +961,8 @@ call fails (for example because the path doesn't exist). .. method:: Path.exists(*, follow_symlinks=True) Return ``True`` if the path points to an existing file or directory. + ``False`` will be returned if the path is invalid, inaccessible or missing. + Use :meth:`Path.stat` to distinguish between these cases. This method normally follows symlinks; to check if a symlink exists, add the argument ``follow_symlinks=False``. @@ -1079,7 +1081,7 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a directory. ``False`` will be returned if the path is invalid, inaccessible or missing, or if it points - to something other than a directory. Use :meth:`Path.exists` to distinguish + to something other than a directory. Use :meth:`Path.stat` to distinguish between these cases. This method normally follows symlinks; to exclude symlinks to directories, @@ -1093,7 +1095,7 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a regular file. ``False`` will be returned if the path is invalid, inaccessible or missing, or if it points - to something other than a regular file. Use :meth:`Path.exists` to + to something other than a regular file. Use :meth:`Path.stat` to distinguish between these cases. This method normally follows symlinks; to exclude symlinks, add the @@ -1133,14 +1135,14 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a symbolic link, even if that symlink is broken. ``False`` will be returned if the path is invalid, inaccessible or missing, or if it points to something other than a symbolic link. Use - :meth:`Path.exists` to distinguish between these cases. + :meth:`Path.stat` to distinguish between these cases. .. method:: Path.is_socket() Return ``True`` if the path points to a Unix socket. ``False`` will be returned if the path is invalid, inaccessible or missing, or if it points - to something other than a Unix socket. Use :meth:`Path.exists` to + to something other than a Unix socket. Use :meth:`Path.stat` to distinguish between these cases. @@ -1148,7 +1150,7 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a FIFO. ``False`` will be returned if the path is invalid, inaccessible or missing, or if it points to something - other than a FIFO. Use :meth:`Path.exists` to distinguish between these + other than a FIFO. Use :meth:`Path.stat` to distinguish between these cases. @@ -1156,7 +1158,7 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a block device. ``False`` will be returned if the path is invalid, inaccessible or missing, or if it points - to something other than a block device. Use :meth:`Path.exists` to + to something other than a block device. Use :meth:`Path.stat` to distinguish between these cases. @@ -1164,7 +1166,7 @@ call fails (for example because the path doesn't exist). Return ``True`` if the path points to a character device. ``False`` will be returned if the path is invalid, inaccessible or missing, or if it points - to something other than a character device. Use :meth:`Path.exists` to + to something other than a character device. Use :meth:`Path.stat` to distinguish between these cases.