You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pathlib: Where does "self._flavour" comes from? (3.11 to 3.12 migration) #104921
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.
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.
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.
Activity
hugovk commentedon 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:
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.CAM-Gerlach commentedon 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.buhtz commentedon 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.
barneygale commentedon May 29, 2023
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