diff --git a/pyfakefs/fake_pathlib.py b/pyfakefs/fake_pathlib.py index b9a1e773..21fd3b74 100644 --- a/pyfakefs/fake_pathlib.py +++ b/pyfakefs/fake_pathlib.py @@ -848,33 +848,15 @@ def touch(self, mode=0o666, exist_ok=True): fake_file.close() self.chmod(mode) - if sys.version_info >= (3, 12): - """These are reimplemented for now because the original implementation - checks the flavour against ntpath/posixpath. - """ - def is_absolute(self): - if self.filesystem.is_windows_fs: - return self.drive and self.root - return os.path.isabs(self._path()) - - def is_reserved(self): - if sys.version_info >= (3, 13): - warnings.warn( - "pathlib.PurePath.is_reserved() is deprecated and scheduled " - "for removal in Python 3.15. Use os.path.isreserved() to detect " - "reserved paths on Windows.", - DeprecationWarning, - ) - if not self.filesystem.is_windows_fs: - return False - if sys.version_info < (3, 13): - if not self._tail or self._tail[0].startswith("\\\\"): - # UNC paths are never reserved. - return False - name = self._tail[-1].partition(".")[0].partition(":")[0].rstrip(" ") - return name.upper() in pathlib._WIN_RESERVED_NAMES - return self.filesystem.isreserved(self._path()) +def _warn_is_reserved_deprecated(): + if sys.version_info >= (3, 13): + warnings.warn( + "pathlib.PurePath.is_reserved() is deprecated and scheduled " + "for removal in Python 3.15. Use os.path.isreserved() to detect " + "reserved paths on Windows.", + DeprecationWarning, + ) class FakePathlibModule: @@ -900,12 +882,40 @@ class PurePosixPath(PurePath): paths""" __slots__ = () + if sys.version_info >= (3, 12): + + def is_reserved(self): + _warn_is_reserved_deprecated() + return False + + def is_absolute(self): + return os.path.isabs(self) class PureWindowsPath(PurePath): """A subclass of PurePath, that represents Windows filesystem paths""" __slots__ = () + if sys.version_info >= (3, 12): + """These are reimplemented because the PurePath implementation + checks the flavour against ntpath/posixpath. + """ + + def is_reserved(self): + _warn_is_reserved_deprecated() + if sys.version_info < (3, 13): + if not self._tail or self._tail[0].startswith("\\\\"): + # UNC paths are never reserved. + return False + name = ( + self._tail[-1].partition(".")[0].partition(":")[0].rstrip(" ") + ) + return name.upper() in pathlib._WIN_RESERVED_NAMES + return os.isreserved(self) + + def is_absolute(self): + return bool(self.drive and self.root) + class WindowsPath(FakePath, PureWindowsPath): """A subclass of Path and PureWindowsPath that represents concrete Windows filesystem paths.