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 - Allow for pathlib.Path
subclassing
#31691
base: main
Are you sure you want to change the base?
gh-68320, gh-88302 - Allow for 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.
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 for making the requested changes! @brettcannon: please review the changes made to this pull request. |
@barneygale now that #99031 is merged, let me know when you're ready for me to review this again. |
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 |
I have made the requested changes; please review again Thanks Brett :) |
Thanks for making the requested changes! @brettcannon: please review the changes made to this pull request. |
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 |
I have made the requested changes; please review again Thanks v much for all your help! |
Thanks for making the requested changes! @brettcannon: please review the changes made to this pull request. |
Users may wish to define subclasses of
pathlib.PurePath
andPath
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