GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-38671: Make sure to return an absolute path in pathlib._WindowsFlavour.resolve() by uranusjr · Pull Request #17716 · python/cpython

Conversation

@uranusjr

@uranusjr uranusjr commented Dec 27, 2019 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

https://bugs.python.org/issue38671

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Lothiraldan, weddige, dquitmann-op, BoboTiG, joreiff, bloussou, wimglenn, cjolowicz, and barneygale reacted with thumbs up emoji
All reactions
  • 👍 9 reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Dec 27, 2019
@bedevere-bot bedevere-bot added the awaiting review label Dec 27, 2019
@uranusjr
uranusjr force-pushed the path-resolve-nonstrict-win branch 3 times, most recently from 78953ba to 34c68f7 Compare December 28, 2019 02:02
eryksun
eryksun reviewed Dec 28, 2019
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ofek

ofek commented Jul 14, 2020

Copy link
Copy Markdown
Contributor

Rebase?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@uranusjr

uranusjr commented Jul 15, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I’ll rebase and change the call to os.path.abspath().


Edit: Done. I ended up adding the os.path.abspath() call later in the function, since the non-absolute s is needed in early parts of the function. I also took the liberty to refactor the function slightly to avoid very deep indentations in the function.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@uranusjr
uranusjr force-pushed the path-resolve-nonstrict-win branch 2 times, most recently from 80498e7 to 54b8063 Compare July 15, 2020 13:46
pitrou
pitrou reviewed Jul 15, 2020
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

pitrou
pitrou reviewed Jul 15, 2020
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

pitrou
pitrou reviewed Jul 15, 2020
View reviewed changes
Comment thread Lib/test/test_pathlib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@uranusjr

uranusjr commented Jul 19, 2020

Copy link
Copy Markdown
Contributor Author

OK, I’ve

  1. Move the unit test under _BasePathTest so it is run for all platforms.
  2. Remove the _getfinalpathname check since it should now be available everywhere. This also allows some additional cleanups that aren’t exactly related to the .resolve() fix.
  3. Use _getfullpathname instead of abspath as suggested.

I split each of these changes into individual commits so they can be easily reverted if needed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@uranusjr
uranusjr force-pushed the path-resolve-nonstrict-win branch from 6b7ebcc to 42fd0b0 Compare July 19, 2020 14:50
@ofek

ofek commented Aug 11, 2020

Copy link
Copy Markdown
Contributor

Will this be in 3.9?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ofek

ofek commented Sep 23, 2020

Copy link
Copy Markdown
Contributor

Any progress?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ofek

ofek commented Oct 5, 2020

Copy link
Copy Markdown
Contributor

Is this just blocked on reviews?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

eryksun
eryksun reviewed Oct 5, 2020
View reviewed changes
Comment thread Lib/pathlib.py Outdated

@eryksun eryksun Oct 5, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Lines 189-191 make a bad assumption that the current working directory (CWD) is a final path. The CWD is an absolute path but not a final path. The assignment should be something like s = str(path) or '.'. In practice it may never be an issue since PurePath.__str__ assigns and returns self._str = self._format_parsed_parts(self._drv, self._root, self._parts) or '.'.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@uranusjr uranusjr Oct 5, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The CWD is an absolute path but not a final path.

TIL.

I like the or '.' approach since it avoids special-casing things, but want @pitrou to take a look since this is inherited from the initial pathlib implementation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
eryksun
eryksun reviewed Oct 5, 2020
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@uranusjr
uranusjr requested a review from pitrou October 5, 2020 08:40
@prescod

prescod commented Mar 9, 2021

Copy link
Copy Markdown

Is this a case of letting the best be the enemy of the good? This bug is a real time-waster and can easily slip into cross-platform code. If the issues @eryksun highlights are pre-existing then perhaps you should merge it and then fix those separately?

dquitmann-op and weddige reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eryksun

eryksun commented Mar 9, 2021 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

@prescod, I just created bpo-43455 for the os.getcwd() issue. It should not hold this issue up.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zooba
zooba reviewed Mar 9, 2021
View reviewed changes
Comment thread Lib/pathlib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ofek

ofek commented Mar 10, 2021

Copy link
Copy Markdown
Contributor

Is it too late for this to be in 3.10?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eryksun

eryksun commented Mar 10, 2021

Copy link
Copy Markdown
Contributor

@ofek, this is a bug fix, not a new feature. Even if it were, new features can be added to 3.10 until the first beta release in May. Hopefully it gets merged into the 3.8 branch in time for the 3.8.9 release in May, since it's the last bug-fix release for 3.8.

ofek and weddige reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

uranusjr added 4 commits April 27, 2021 16:28
@uranusjr
Prepend cwd if resolve can't find existing prefix
e503cd6
This guarentees we are returning an absolute path when the input `path`
is relative. Nothing would change if `path` is already absolute.
@uranusjr
Use os.path.abspath() as fallback as suggested
3f9d1b8
@uranusjr
Use early returns to reduce indentation level
612b7f6
@uranusjr
Test non-exist resolve on all platforms
7cff82e
@uranusjr
Use nt._getfullpathname instead of os.path.abspath
8f20c10
@uranusjr
uranusjr force-pushed the path-resolve-nonstrict-win branch from 42fd0b0 to 8f20c10 Compare April 27, 2021 08:33
@uranusjr

uranusjr commented Apr 27, 2021

Copy link
Copy Markdown
Contributor Author

Strong nudge.

Hopefully it gets merged into the 3.8 branch in time for the 3.8.9 release in May

This is our last chance.

cjolowicz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ofek

ofek commented May 2, 2021

Copy link
Copy Markdown
Contributor

Needs one final rebase

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@uranusjr

uranusjr commented May 2, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I’ve rebased this multiple times and this time the new incoming changes is too much for me. I give up. Someone else can take over.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@uranusjr uranusjr closed this May 2, 2021
@barneygale barneygale mentioned this pull request May 17, 2021
bpo-38671: Add test that pathlib.Path.resolve() returns an absolute path. #26184
Merged
@uranusjr
uranusjr deleted the path-resolve-nonstrict-win branch March 3, 2022 10:04
@eryksun eryksun mentioned this pull request Jun 21, 2022
pathlib mistakenly assumes os.getcwd() is a resolved path in Windows #87621
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@eryksun eryksun eryksun left review comments
@pfmoore pfmoore pfmoore left review comments
@zooba zooba zooba left review comments
@pitrou pitrou Awaiting requested review from pitrou

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

9 participants

@uranusjr @ofek @prescod @eryksun @pfmoore @zooba @pitrou @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.