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 should allow converting to absolute paths without resolving symlinks #69200
Comments
There doesn't seem to be any helper in pathlib to expand a relative path to an absolute path *without* resolving symlinks. For example, if I want to convert |
pathlib.Path.cwd() / pathlib.Path('some/path') |
There's a public method that's almost what you want: >>> print(pathlib.Path.absolute.__doc__)
Return an absolute version of this path. This function works
even if the path doesn't point to anything.
However, it appears to be only accidentally public. It isn't tested; it isn't mentioned in the docs; and it doesn't do the [expected] path normalization. Currently it's used as a default in resolve() if self._flavour.resolve(self) returns None. |
Yes, this wasn't meant to be a public method really. I'm still on the fence as to whether we should expose something like this. What is your use case? |
The idiom of My use case was that I had an equality check like this failing: Even if that's fixed, I would still expect to run into cases where I wanted to print specifically the relative or absolute path in informational messages and would not want to follow symlinks (e.g., in "Requested path X not found", the user would recognize the absolute path as the one they entered but not necessarily the symlink-resolved version). |
Le 08/09/2015 01:21, David Barnett a écrit :
Semantically, the paths are equal only in that particular system Currently the way to implement "absolute" comparison is to call
Yes... and yet that may be misleading, since the "absolute" path I'll have to think about this one a bit more. |
Right, and to clarify a bit further why I didn't just use A.resolve() == B.resolve() from the beginning, this is in a unit test where the equality check wasn't in my code. I wanted to assert I received a certain call on my mock, like |
And the symlinks for my paths refer to really cryptic hashes in a virtual filesystem for the tests, so rendering them into the assertion failed errors would really make the failure messages hard to interpret. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: