Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-38671: Make sure to return an absolute path in pathlib._WindowsFlavour.resolve() #17716

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 5 commits into from

Conversation

uranusjr
Copy link
Contributor

@uranusjr uranusjr commented 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
@ofek
Copy link
Contributor

ofek commented Jul 14, 2020

Rebase?

@uranusjr
Copy link
Contributor Author

uranusjr commented Jul 15, 2020

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.

@uranusjr uranusjr force-pushed the path-resolve-nonstrict-win branch 2 times, most recently from 80498e7 to 54b8063 Compare July 15, 2020 13:46
@uranusjr
Copy link
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.

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

ofek commented Aug 11, 2020

Will this be in 3.9?

@ofek
Copy link
Contributor

ofek commented Sep 23, 2020

Any progress?

@ofek
Copy link
Contributor

ofek commented Oct 5, 2020

Is this just blocked on reviews?

@@ -194,25 +189,23 @@ def resolve(self, path, strict=False):
s = str(path)
if not s:
return os.getcwd()
if strict:
Copy link
Contributor

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 '.'.

Copy link
Contributor Author

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.

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

prescod commented Mar 9, 2021

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?

@eryksun
Copy link
Contributor

eryksun commented Mar 9, 2021

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

@ofek
Copy link
Contributor

ofek commented Mar 10, 2021

Is it too late for this to be in 3.10?

@eryksun
Copy link
Contributor

eryksun commented Mar 10, 2021

@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.

This guarentees we are returning an absolute path when the input `path`
is relative. Nothing would change if `path` is already absolute.
@uranusjr uranusjr force-pushed the path-resolve-nonstrict-win branch from 42fd0b0 to 8f20c10 Compare April 27, 2021 08:33
@uranusjr
Copy link
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.

@ofek
Copy link
Contributor

ofek commented May 2, 2021

Needs one final rebase

@uranusjr
Copy link
Contributor Author

uranusjr commented May 2, 2021

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.

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.

9 participants