Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Windows-to-POSIX separator conversion via PurePosixPath(PureWindowsPath(...))) #125012

Open
barneygale opened this issue Oct 5, 2024 · 0 comments
Labels
topic-pathlib type-feature A feature request or enhancement

Comments

@barneygale
Copy link
Contributor

barneygale commented Oct 5, 2024

Feature or enhancement

This was probably never an intentional feature, and results in subtle behaviour:

>>> from pathlib import PurePosixPath, PureWindowsPath
>>> from os import fspath
>>> p = PureWindowsPath('foo', 'bar')
>>> PurePosixPath(p)
PurePosixPath('foo/bar')
>>> p = fspath(p)
>>> PurePosixPath(p)
PurePosixPath('foo\\bar')

PurePath is documented as accepting os.PathLike objects, and so the additional os.fspath() call shouldn't really make a difference. See #103631 for why it does (spoiler: backwards-compatibility).

Folks can use PurePosixPath(PureWindowsPath().as_posix()) instead, which makes it more explicit that backwards-to-forwards slash conversion is desired.

Linked PRs

@barneygale barneygale added type-feature A feature request or enhancement topic-pathlib labels Oct 5, 2024
barneygale added a commit to barneygale/cpython that referenced this issue Oct 23, 2024
… separators

Make `PurePosixPath(PureWindowsPath(...))` emit a `FutureWarning`
indicating that implicit conversion of backward slashes to forward slashes
will cease in a future Python release. This feature isn't documented, and
it wasn't tested until I accidentally broke it a couple of releases ago!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-pathlib type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant