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.
This commit is contained in:
Barney Gale 2023-12-22 15:11:16 +00:00 committed by GitHub
parent 45e09f921b
commit 237e2cff00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 15 deletions

View file

@ -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."""