Skip to content

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

Open
@barneygale

Description

@barneygale

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions