python / python/cpython

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

Open
#125,012 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

topic-pathlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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
  • gh-125863

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the pathlib PurePath handling described in the issue and the linked PR gh-125863. Compare the PureWindowsPath and PurePosixPath examples, then verify that the deprecated conversion behavior and the explicit as_posix() alternative are covered by the resulting changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.