]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
Add `pathlib._abc.PathModuleBase` (#113893)
authorBarney Gale <barney.gale@gmail.com>
Sun, 14 Jan 2024 21:49:53 +0000 (21:49 +0000)
committerGitHub <noreply@github.com>
Sun, 14 Jan 2024 21:49:53 +0000 (21:49 +0000)
commitca6cf56330ae7751819b62748f33f23d98596703
tree461b2a8b3651a1570736ff9cbed4832671d813bd
parentc2808431b32fa7bc0d222d4549389f781f1a7333
Add `pathlib._abc.PathModuleBase` (#113893)

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.
Lib/pathlib/__init__.py
Lib/pathlib/_abc.py
Lib/test/test_pathlib/test_pathlib.py
Lib/test/test_pathlib/test_pathlib_abc.py