mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
GH-104898: Add __slots__ to os.PathLike (GH-104899)
This commit is contained in:
parent
fea8632ec6
commit
bd1b6228d1
4 changed files with 10 additions and 5 deletions
|
@ -1079,6 +1079,8 @@ class PathLike(abc.ABC):
|
||||||
|
|
||||||
"""Abstract base class for implementing the file system path protocol."""
|
"""Abstract base class for implementing the file system path protocol."""
|
||||||
|
|
||||||
|
__slots__ = ()
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def __fspath__(self):
|
def __fspath__(self):
|
||||||
"""Return the file system path representation of the object."""
|
"""Return the file system path representation of the object."""
|
||||||
|
|
|
@ -233,7 +233,7 @@ class _PathParents(Sequence):
|
||||||
return "<{}.parents>".format(type(self._path).__name__)
|
return "<{}.parents>".format(type(self._path).__name__)
|
||||||
|
|
||||||
|
|
||||||
class PurePath(object):
|
class PurePath(os.PathLike):
|
||||||
"""Base class for manipulating paths without I/O.
|
"""Base class for manipulating paths without I/O.
|
||||||
|
|
||||||
PurePath represents a filesystem path and offers operations which
|
PurePath represents a filesystem path and offers operations which
|
||||||
|
@ -707,10 +707,6 @@ class PurePath(object):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Can't subclass os.PathLike from PurePath and keep the constructor
|
|
||||||
# optimizations in PurePath.__slots__.
|
|
||||||
os.PathLike.register(PurePath)
|
|
||||||
|
|
||||||
|
|
||||||
class PurePosixPath(PurePath):
|
class PurePosixPath(PurePath):
|
||||||
"""PurePath subclass for non-Windows systems.
|
"""PurePath subclass for non-Windows systems.
|
||||||
|
|
|
@ -4640,6 +4640,12 @@ class TestPEP519(unittest.TestCase):
|
||||||
def test_pathlike_class_getitem(self):
|
def test_pathlike_class_getitem(self):
|
||||||
self.assertIsInstance(os.PathLike[bytes], types.GenericAlias)
|
self.assertIsInstance(os.PathLike[bytes], types.GenericAlias)
|
||||||
|
|
||||||
|
def test_pathlike_subclass_slots(self):
|
||||||
|
class A(os.PathLike):
|
||||||
|
__slots__ = ()
|
||||||
|
def __fspath__(self):
|
||||||
|
return ''
|
||||||
|
self.assertFalse(hasattr(A(), '__dict__'))
|
||||||
|
|
||||||
class TimesTests(unittest.TestCase):
|
class TimesTests(unittest.TestCase):
|
||||||
def test_times(self):
|
def test_times(self):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add missing :attr:`~object.__slots__` to :class:`os.PathLike`.
|
Loading…
Add table
Add a link
Reference in a new issue