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

GH-125069: Fix inconsistent joining in WindowsPath(PosixPath(...)) #125156

Merged
merged 6 commits into from
Oct 13, 2024

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented Oct 8, 2024

PurePath.__init__() incorrectly uses the _raw_paths of a given PurePath object with a different flavour, even though the procedure to join path segments can differ between flavours.

This change makes the _raw_paths-enabled deferred joining apply only when the path flavours match.

…..))`

`PurePath.__init__()` incorrectly uses the `_raw_paths` of a given
`PurePath` object with a different flavour, even though the procedure to
join path segments can differ between flavours.

This change makes the `_raw_paths`-enabled deferred joining apply _only_
when the path flavours match.
…RP0Mx.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@barneygale
Copy link
Contributor Author

Some background info: the _raw_paths-enabled deferred joining is meant to speed up this sort of thing:

str(Path('a') / 'b' / 'c' / 'd' / 'e')

Without deferred joining, this requires four calls to os.path.join():

  • join('a', 'b')
  • join('a/b', 'c')
  • join('a/b/c', 'd')
  • join('a/b/c/d', 'e')

With deferred joining, it calls join() once: join('a', 'b', 'c', 'd', 'e'). This also saves three calls to os.path.splitroot().

Copy link
Contributor

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

LGTM.

@barneygale
Copy link
Contributor Author

Thank you very much for the review, @picnixz

@barneygale barneygale enabled auto-merge (squash) October 13, 2024 17:36
@picnixz
Copy link
Contributor

picnixz commented Oct 13, 2024

Always happy to review them!

@barneygale barneygale merged commit cb8e599 into python:main Oct 13, 2024
34 checks passed
@miss-islington-app
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 13, 2024
…..))` (pythonGH-125156)

`PurePath.__init__()` incorrectly uses the `_raw_paths` of a given
`PurePath` object with a different flavour, even though the procedure to
join path segments can differ between flavours.

This change makes the `_raw_paths`-enabled deferred joining apply _only_
when the path flavours match.

(cherry picked from commit cb8e599)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@miss-islington-app
Copy link

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

cherry_picker cb8e5995d89d9b90e83cf43310ec50e177484e70 3.12

@bedevere-app
Copy link

bedevere-app bot commented Oct 13, 2024

GH-125409 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Oct 13, 2024
barneygale added a commit to barneygale/cpython that referenced this pull request Oct 13, 2024
…xPath(...))` (pythonGH-125156)

`PurePath.__init__()` incorrectly uses the `_raw_paths` of a given
`PurePath` object with a different flavour, even though the procedure to
join path segments can differ between flavours.

This change makes the `_raw_paths`-enabled deferred joining apply _only_
when the path flavours match.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>.
(cherry picked from commit cb8e599)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Oct 13, 2024

GH-125410 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Oct 13, 2024
barneygale added a commit that referenced this pull request Oct 13, 2024
…...))` (GH-125156) (#125409)

`PurePath.__init__()` incorrectly uses the `_raw_paths` of a given
`PurePath` object with a different flavour, even though the procedure to
join path segments can differ between flavours.

This change makes the `_raw_paths`-enabled deferred joining apply _only_
when the path flavours match.

(cherry picked from commit cb8e599)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
barneygale added a commit that referenced this pull request Oct 13, 2024
…...))` (GH-125156) (#125410)

`PurePath.__init__()` incorrectly uses the `_raw_paths` of a given
`PurePath` object with a different flavour, even though the procedure to
join path segments can differ between flavours.

This change makes the `_raw_paths`-enabled deferred joining apply _only_
when the path flavours match.

(cherry picked from commit cb8e599)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
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.

3 participants