summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2023-12-22 15:11:16 (GMT)
committerGitHub <noreply@github.com>2023-12-22 15:11:16 (GMT)
commit237e2cff00cca49db47bcb7ea13683a4d9ad1ea5 (patch)
treef1d2f5db8d04d263b2c2b3808f31a800df4a45ac /Lib/pathlib
parent45e09f921be55e23bed19b5db4c95ce7bd7aad6b (diff)
downloadcpython-237e2cff00cca49db47bcb7ea13683a4d9ad1ea5.zip
cpython-237e2cff00cca49db47bcb7ea13683a4d9ad1ea5.tar.gz
cpython-237e2cff00cca49db47bcb7ea13683a4d9ad1ea5.tar.bz2
GH-110109: Fix misleading `pathlib._abc.PurePathBase` repr (#113376)
`PurePathBase.__repr__()` produces a string like `MyPath('/foo')`. This repr is incorrect/misleading when a subclass's `__init__()` method is customized, which I expect to be the very common. This commit moves the `__repr__()` method to `PurePath`, leaving `PurePathBase` with the default `object` repr. No user-facing changes because the `pathlib._abc` module remains private.
Diffstat (limited to 'Lib/pathlib')
-rw-r--r--Lib/pathlib/__init__.py3
-rw-r--r--Lib/pathlib/_abc.py3
2 files changed, 3 insertions, 3 deletions
diff --git a/Lib/pathlib/__init__.py b/Lib/pathlib/__init__.py
index b020d2d..4a8bee6 100644
--- a/Lib/pathlib/__init__.py
+++ b/Lib/pathlib/__init__.py
@@ -99,6 +99,9 @@ class PurePath(_abc.PurePathBase):
# when pickling related paths.
return (self.__class__, self.parts)
+ def __repr__(self):
+ return "{}({!r})".format(self.__class__.__name__, self.as_posix())
+
def __fspath__(self):
return str(self)
diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py
index 4808d0e..fc4b644 100644
--- a/Lib/pathlib/_abc.py
+++ b/Lib/pathlib/_abc.py
@@ -282,9 +282,6 @@ class PurePathBase:
slashes."""
return str(self).replace(self.pathmod.sep, '/')
- def __repr__(self):
- return "{}({!r})".format(self.__class__.__name__, self.as_posix())
-
@property
def drive(self):
"""The drive prefix (letter or UNC path), if any."""