Skip to content

Commit

Permalink
gh-68320, gh-88302 - Allow for private pathlib.Path subclassing (GH…
Browse files Browse the repository at this point in the history
…-31691)

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 change 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.

Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Brett Cannon <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
Co-authored-by: Eryk Sun <[email protected]>
  • Loading branch information
5 people committed Dec 23, 2022
1 parent 5d84966 commit a68e585
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 232 deletions.
Loading

0 comments on commit a68e585

Please sign in to comment.