Skip to content
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

pathlib: Where does "self._flavour" comes from? (3.11 to 3.12 migration) #104921

Closed
buhtz opened this issue May 25, 2023 · 4 comments
Closed

pathlib: Where does "self._flavour" comes from? (3.11 to 3.12 migration) #104921

buhtz opened this issue May 25, 2023 · 4 comments
Labels
3.12 bugs and security fixes pending The issue will be closed if no feedback is provided stdlib Python modules in the Lib dir topic-pathlib

Comments

@buhtz
Copy link

buhtz commented May 25, 2023

This question is related to Python 3.12.

self._raw_path = self._flavour.join(*paths)

This is the first occurrence of self._flavour in pathlib.py. I don't see where this object is set. I can't find the string self._flavour = somewhere in the repo. I'm confused.

Background:
I try to figuring out why pathlib._Flavour.parse_parts() (and the whole class) was removed from Python 3.11 to 3.12. I can not see this in the CHANGELOG. And I'm not skilled enough with git to find the related commit.

@hugovk hugovk added topic-pathlib stdlib Python modules in the Lib dir 3.12 bugs and security fixes labels May 25, 2023
@hugovk
Copy link
Member

hugovk commented May 25, 2023

Thank you for testing the beta!

pathlib._Flavour was removed in #31691.

The linked issues are gh-68320, gh-88302. From the latter:

Following bpo-39899, bpo-43757 and bpo-43012, pathlib._Flavour and its subclasses are looking a bit pointless.

The implementations of is_reserved() and make_uri() (~as_uri()) can be readily moved to into PurePosixPath and PureWindowsPath, which removes some indirection. This follows the pattern of OS-specific stuff in PosixPath and WindowsPath.

The remaining methods, such as splitroot(), can be pulled into Pure*Path with an underscore prefix.

I'm generally a believer in composition over inheritance, but in this case _Flavour seems too small and too similar to PurePath to separate out into 3 extra classes.

There should be no impact on public APIs or performance.

I expect there was no CHANGELOG entry because the undescores indicate these are private and not part of the public API, and pyfakefs will need refactoring to use something else.

cc @barneygale


PS I did git log -S _Flavour Lib/pathlib.py to find the most recent commit mentioning the class, including deletes.

@hugovk hugovk added the pending The issue will be closed if no feedback is provided label May 25, 2023
@CAM-Gerlach
Copy link
Member

Also, just to note, _parse_parts itself (likewise still a private method) was replaced with _parse_path in PR #102789 , to address issues #76846 and #85281 . Presumably, the intention is to properly subclass Path rather than relying on private internal-only members, though @barneygale is the expert and can likely advise you what's best for your use case much more specifically.

@buhtz
Copy link
Author

buhtz commented May 25, 2023

Awesome! Great!
Thanks a lot for helping and explaining. I learned a lot.

From my point of view this Issue can be closed.

@hugovk hugovk closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2023
@barneygale
Copy link
Contributor

For posterity, the motivation/explanation for the removal of the flavour classes can be found here: https://discuss.python.org/t/make-pathlib-extensible/3428/42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes pending The issue will be closed if no feedback is provided stdlib Python modules in the Lib dir topic-pathlib
Projects
None yet
Development

No branches or pull requests

4 participants