Skip to content

Add pathlib._abc.PathModuleBase - #113893

Merged
barneygale merged 6 commits into
python:mainfrom
barneygale:pathmodulebase
Jan 14, 2024
Merged

barneygale merged 6 commits into
python:mainfrom
barneygale:pathmodulebase

Conversation

@barneygale

@barneygale barneygale commented Jan 10, 2024 •

Copy link
Copy Markdown
Contributor

Path modules provide a subset of the os.path API, specifically those functions needed to provide PurePathBase functionality. Each PurePathBase subclass references its path module via a pathmod class attribute.

This commit adds a new PathModuleBase class, which provides abstract methods that unconditionally raise UnsupportedOperation. An instance of this class is assigned to PurePathBase.pathmod, replacing posixpath. As a result, PurePathBase is no longer POSIX-y by default, and all its methods raise UnsupportedOperation courtesy of pathmod.

Users who subclass PurePathBase or PathBase should choose the path syntax by setting pathmod to posixpath, ntpath, os.path, or their own subclass of PathModuleBase, as circumstances demand.

If/when we make the ABCs public, we may wish to rename this class and the pathmod attribute to something less misleading, like "flavour".

Downstream issue:

Path modules provide a subset of the `os.path` API, specifically those
functions needed to provide `PurePathBase` functionality. Each
`PurePathBase` subclass references its path module via a `pathmod` class
attribute.

This commit adds a new `PathModuleBase` class, which provides abstract
methods that unconditionally raise `UnsupportedOperation`. An instance of
this class is assigned to `PurePathBase.pathmod`, replacing `posixpath`.
As a result, `PurePathBase` is no longer POSIX-y by default, and almost[^1]
all its methods raise `UnsupportedOperation` courtesy of `pathmod`.

Users who subclass `PurePathBase` or `PathBase` should choose the path
syntax by setting `pathmod` to `posixpath`, `ntpath`, `os.path`, or their
own subclass of `PathModuleBase`, as circumstances demand.

[^1] Except `joinpath()`, `__truediv__()`, `__rtruediv__()`. See pythonGH-113888.
@barneygale
barneygale merged commit ca6cf56 into python:main Jan 14, 2024
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
Path modules provide a subset of the `os.path` API, specifically those
functions needed to provide `PurePathBase` functionality. Each
`PurePathBase` subclass references its path module via a `pathmod` class
attribute.

This commit adds a new `PathModuleBase` class, which provides abstract
methods that unconditionally raise `UnsupportedOperation`. An instance of
this class is assigned to `PurePathBase.pathmod`, replacing `posixpath`.
As a result, `PurePathBase` is no longer POSIX-y by default, and
all its methods raise `UnsupportedOperation` courtesy of `pathmod`.

Users who subclass `PurePathBase` or `PathBase` should choose the path
syntax by setting `pathmod` to `posixpath`, `ntpath`, `os.path`, or their
own subclass of `PathModuleBase`, as circumstances demand.
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Path modules provide a subset of the `os.path` API, specifically those
functions needed to provide `PurePathBase` functionality. Each
`PurePathBase` subclass references its path module via a `pathmod` class
attribute.

This commit adds a new `PathModuleBase` class, which provides abstract
methods that unconditionally raise `UnsupportedOperation`. An instance of
this class is assigned to `PurePathBase.pathmod`, replacing `posixpath`.
As a result, `PurePathBase` is no longer POSIX-y by default, and
all its methods raise `UnsupportedOperation` courtesy of `pathmod`.

Users who subclass `PurePathBase` or `PathBase` should choose the path
syntax by setting `pathmod` to `posixpath`, `ntpath`, `os.path`, or their
own subclass of `PathModuleBase`, as circumstances demand.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Path modules provide a subset of the `os.path` API, specifically those
functions needed to provide `PurePathBase` functionality. Each
`PurePathBase` subclass references its path module via a `pathmod` class
attribute.

This commit adds a new `PathModuleBase` class, which provides abstract
methods that unconditionally raise `UnsupportedOperation`. An instance of
this class is assigned to `PurePathBase.pathmod`, replacing `posixpath`.
As a result, `PurePathBase` is no longer POSIX-y by default, and
all its methods raise `UnsupportedOperation` courtesy of `pathmod`.

Users who subclass `PurePathBase` or `PathBase` should choose the path
syntax by setting `pathmod` to `posixpath`, `ntpath`, `os.path`, or their
own subclass of `PathModuleBase`, as circumstances demand.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant