python / python/cpython

Document pathlib with_segments duck typing for path object arguments

Open
#153,390 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

docs
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Some pathlib methods use the presence of a with_segments attribute to decide whether an argument is already a path object.

This behavior was changed in gh-128520 / GH-130199 for Python 3.14. The main pathlib reference documents PurePath.with_segments(), but it does not currently mention that methods such as PurePath.match() and Path.rename() use with_segments as this duck-typed marker.

This can surprise authors of path-like or path-adjacent classes that define with_segments without implementing os.PathLike. The docs should describe the current behavior so subclass and third-party path authors have a clear contract to work from.

Linked PRs
  • gh-153394

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 in the main pathlib reference at the PurePath.with_segments() documentation and review the references to PurePath.match() and Path.rename(). Document that the presence of with_segments is used as a duck-typed path-object marker, including the implication for path-like and path-adjacent classes; confirm the rendered documentation explains the current Python 3.14 behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.