mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
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.
This commit is contained in:
parent
ff5e131df5
commit
a0d3d3ec9d
4 changed files with 87 additions and 60 deletions
|
@ -1,7 +1,6 @@
|
|||
import functools
|
||||
import io
|
||||
import ntpath
|
||||
import os
|
||||
import posixpath
|
||||
import sys
|
||||
import warnings
|
||||
|
@ -204,7 +203,7 @@ class PurePathBase:
|
|||
# work from occurring when `resolve()` calls `stat()` or `readlink()`.
|
||||
'_resolving',
|
||||
)
|
||||
pathmod = os.path
|
||||
pathmod = posixpath
|
||||
|
||||
def __init__(self, *paths):
|
||||
self._raw_paths = paths
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue