New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-68320, gh-88302 - Fix pathlib.Path
subclassing.
#31691
base: main
Are you sure you want to change the base?
gh-68320, gh-88302 - Fix pathlib.Path
subclassing.
#31691
Conversation
Users may wish to define subclasses of `pathlib.Path` to add or modify existing methods. Before this change, attempting to instantiate a subclass raised an exception like: AttributeError: type object 'PPath' has no attribute '_flavour' Previously the `_flavour` attribute was assigned as follows: PurePath._flavour = xxx not set!! xxx PurePosixPath._flavour = _PosixFlavour() PureWindowsPath._flavour = _WindowsFlavour() This commit replaces it with a `_pathmod` attribute, set as follows: PurePath._pathmod = os.path PurePosixPath._pathmod = posixpath PureWindowsPath._pathmod = ntpath Functionality from `_PosixFlavour` and `_WindowsFlavour` is moved into `PurePath` as underscored-prefixed classmethods. Flavours are removed.
Misc/NEWS.d/next/Library/2022-03-05-02-14-09.bpo-24132.W6iORO.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
…ygale/cpython into bpo-44136-remove-pathlib-flavour-2
Makes the code a little more direct.
Hey @brettcannon, just bumping this PR in case it dropped off your radar. |
@barneygale it hasn't, but my PR review queue is 11 PRs deep, this is in position 7, and I have worry about getting PEP 594 done in time for 3.11b1. Plus I have some stuff I need to get done for work this month which is eating into my paid OSS time. |
pathlib.Path
subclassing.pathlib.Path
subclassing.
Most of the comments are either code touch-ups or asking to make the code more self-describing.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Co-authored-by: Brett Cannon <brett@python.org>
Thanks @brettcannon, working to address your feedback now. Some of your comments relate to the I'm happy to fix up formatting and whatnot, but I don't want to modify the implementations of those methods too much here. It adds undue risk to the overall PR as it's possible we'll change behaviour without realising it. And in this particular case, the deficiencies in Does that go some of the way towards explaining why I'm mostly leaving these implementations alone, aside moving them from the "flavour" classes into |
I didn't expect the Spanish Inquisition! |
Nobody expects the Spanish Inquisition! @brettcannon: please review the changes made to this pull request. |
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Users may wish to define subclasses of
pathlib.Path
to add or modify existing methods. Before this change, attempting to instantiate a subclass raised an exception like:Previously the
_flavour
attribute was assigned as follows:It's now set as follows:
Functionality from
_PosixFlavour
and_WindowsFlavour
is moved intoPurePath
as underscored-prefixed classmethods. Flavour classes are removed.A deeper dive into this patch can be read here: https://discuss.python.org/t/make-pathlib-extensible/3428/42
Fixes #68320 #88302