]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-110109: pathlib ABCs: do not vary path syntax by host OS. (#113219)
authorBarney Gale <barney.gale@gmail.com>
Fri, 22 Dec 2023 18:09:50 +0000 (18:09 +0000)
committerGitHub <noreply@github.com>
Fri, 22 Dec 2023 18:09:50 +0000 (18:09 +0000)
commita0d3d3ec9ddd35514aa8db68b2fe9b8151cfc0a6
tree3e7ab55c824f269b6e93c53ae8d6f8805c613e5d
parentff5e131df5f374f72579b970856dc5646e8b836c
GH-110109: pathlib ABCs: do not vary path syntax by host OS. (#113219)

Change the value of `pathlib._abc.PurePathBase.pathmod` from `os.path` to
`posixpath`.

User subclasses of `PurePathBase` and `PathBase` previously used the host
OS's path syntax, e.g. backslashes as separators on Windows. This is wrong
in most use cases, and likely to catch developers out unless they test on
both Windows and non-Windows machines.

In this patch we change the default to POSIX syntax, regardless of OS. This
is somewhat arguable (why not make all aspects of syntax abstract and
individually configurable?) but an improvement all the same.

This change has no effect on `PurePath`, `Path`, nor their subclasses. Only
private APIs are affected.
Lib/pathlib/__init__.py
Lib/pathlib/_abc.py
Lib/test/test_pathlib/test_pathlib.py
Lib/test/test_pathlib/test_pathlib_abc.py