Visitar URL original
pathlib: Where does "self._flavour" comes from? (3.11 to 3.12 migration) · Issue #104921 · python/cpython · GitHub
Skip to content

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

Description

@buhtz

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.

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    3.12only security fixes
    on May 25, 2023
  2. hugovk commented on May 25, 2023

    @hugovk
    Member

    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.

  3. added
    pendingThe issue will be closed if no feedback is provided
    on May 25, 2023
  4. CAM-Gerlach commented on May 25, 2023

    @CAM-Gerlach
    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.

  5. buhtz commented on May 25, 2023

    @buhtz
    Author

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

    From my point of view this Issue can be closed.

  6. barneygale commented on May 29, 2023

    @barneygale
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixespendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytopic-pathlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions