Skip to content

bpo-43525: Highlight pathlib operator behavior with anchored paths #24900

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Doc/library/pathlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ The slash operator helps create child paths, similarly to :func:`os.path.join`::
>>> '/usr' / q
PurePosixPath('/usr/bin')

Note that a string containing a leading '`/`' character will be considered
an absolute path, making the last to be taken as the anchor for the new
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"last"? "last one"? The phrasing is copied from pathlib.PurePath:

When several absolute paths are given, the last is taken as an anchor (mimicking os.path.join()’s behaviour):

path object (mimicking :func:`os.path.join`'s behaviour)::

>>> p = PurePath('/usr')
>>> p / '/bin'
PurePosixPath('/bin')
>>> p / '/bin' / '/python'
PurePosixPath('/python')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this ok? I didn't want to use python3 to not make the example susceptible to bit-rot 😆

I couldn't think of another executable. Maybe a different path would be a better example?

Maybe I'm overthinking it! 😆 🤣


A path object can be used anywhere an object implementing :class:`os.PathLike`
is accepted::

Expand Down