Repository navigation
pathlib: Where does "self._flavour" comes from? (3.11 to 3.12 migration) #104921
Description
Activity
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory3.12only security fixesonly security fixes
on May 25, 2023 Thank you for testing the beta!
pathlib._Flavourwas removed in #31691.The linked issues are gh-68320, gh-88302. From the latter:
Following bpo-39899, bpo-43757 and bpo-43012,
pathlib._Flavourand its subclasses are looking a bit pointless.The implementations of
is_reserved()andmake_uri()(~as_uri()) can be readily moved to intoPurePosixPathandPureWindowsPath, which removes some indirection. This follows the pattern of OS-specific stuff inPosixPathandWindowsPath.The remaining methods, such as
splitroot(), can be pulled intoPure*Pathwith an underscore prefix.I'm generally a believer in composition over inheritance, but in this case
_Flavourseems too small and too similar toPurePathto 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.pyto find the most recent commit mentioning the class, including deletes.- addedpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on May 25, 2023 Also, just to note,
_parse_partsitself (likewise still a private method) was replaced with_parse_pathin PR #102789 , to address issues #76846 and #85281 . Presumably, the intention is to properly subclassPathrather 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.Awesome! Great!
Thanks a lot for helping and explaining. I learned a lot.From my point of view this Issue can be closed.
Reacted by Hugo van KemenadeFor 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
Reacted by Christian Buhtz
This question is related to Python 3.12.
cpython/Lib/pathlib.py
Line 319 in 278030a
This is the first occurrence of
self._flavourinpathlib.py. I don't see where this object is set. I can't find the stringself._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.