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

pathlib ABCs: remove duplicate realpath() implementation. #119178

Merged
merged 7 commits into from
Jun 5, 2024

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented May 19, 2024

Add private posixpath._realpath() function, which is a generic version of realpath() that can be parameterised with string tokens (sep, curdir, pardir) and query functions (getcwd, lstat, readlink). Also add support for limiting the number of symlink traversals.

In the private pathlib._abc.PathBase class, call posixpath._realpath() and remove our re-implementation of the same algorithm. This speeds up PathBase.resolve() because we instantiate fewer PathBase objects, and because _realpath() caches symlink targets.

No change to any public APIs, either in posixpath or pathlib.

Add private `posixpath._realpath()` function, which is a generic version of
`realpath()` that can be parameterised with string tokens (`sep`, `curdir`,
`pardir`) and query functions (`getcwd`, `lstat`, `readlink`). Also add
support for limiting the number of symlink traversals.

In the private `pathlib._abc.PathBase` class, call `posixpath._realpath()`
and remove our re-implementation of the same algorithm. This speeds up
`PathBase.resolve()` because we instantiate fewer `PathBase` objects, and
because `_realpath()` caches symlink targets.
Lib/posixpath.py Outdated Show resolved Hide resolved
Lib/pathlib/_abc.py Outdated Show resolved Hide resolved
Lib/posixpath.py Outdated Show resolved Hide resolved
Lib/posixpath.py Outdated Show resolved Hide resolved
Copy link
Contributor

@nineteendo nineteendo left a comment

Choose a reason for hiding this comment

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

Don't hard code the error message, like eryksun pointed out in the other pull request.

Lib/posixpath.py Outdated Show resolved Hide resolved
Lib/posixpath.py Outdated Show resolved Hide resolved
Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
@barneygale barneygale merged commit e83ce85 into python:main Jun 5, 2024
31 checks passed
barneygale added a commit to barneygale/cpython that referenced this pull request Jun 5, 2024
…19178)

Add private `posixpath._realpath()` function, which is a generic version of `realpath()` that can be parameterised with string tokens (`sep`, `curdir`, `pardir`) and query functions (`getcwd`, `lstat`, `readlink`). Also add support for limiting the number of symlink traversals.

In the private `pathlib._abc.PathBase` class, call `posixpath._realpath()` and remove our re-implementation of the same algorithm.

No change to any public APIs, either in `posixpath` or `pathlib`.

Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
@barneygale
Copy link
Contributor Author

Will backport to make backporting #120127 easier.

@barneygale barneygale added needs backport to 3.13 bugs and security fixes labels Jun 5, 2024
@miss-islington-app
Copy link

Thanks @barneygale for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

2 similar comments
@miss-islington-app
Copy link

Thanks @barneygale for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @barneygale for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @barneygale, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker e83ce850f433fd8bbf8ff4e8d7649b942639db31 3.13

@barneygale
Copy link
Contributor Author

Ah foo, nevermind then!

@miss-islington-app
Copy link

Sorry, @barneygale, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker e83ce850f433fd8bbf8ff4e8d7649b942639db31 3.13

@barneygale barneygale removed needs backport to 3.13 bugs and security fixes labels Jun 5, 2024
@miss-islington-app
Copy link

Sorry, @barneygale, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker e83ce850f433fd8bbf8ff4e8d7649b942639db31 3.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants