classification
Title: pathlib.Path.__eq__ should test normalized path
Type: enhancement Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: ascola, eryksun
Priority: normal Keywords:

Created on 2020-11-28 20:38 by ascola, last changed 2020-11-29 01:34 by eryksun. This issue is now closed.

Messages (3)
msg382015 - (view) Author: Austin Scola (ascola) Date: 2020-11-28 20:38
I think it would be more useful for the pathlib.Path.__eq__ method to test the normalized path (not sure if normalized is the right terminology here).

As a concrete example I think that `PosixPath('/foo')` should equal `PosixPath('/foo/../foo')`. This is because functionally the two paths are equivalent.
msg382019 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2020-11-28 22:02
The __eq__ method would have to do a full resolve(), which is expensive and may fail. One can't simply resolve "/foo/symlink/.." as "/foo", where "symlink" is a filesystem symlink. The target has to be resolved before ".." is evaluated, and the link may be invalid or inaccessible. This isn't relevant in Windows because it normalizes ".." components in an opened path with string-based processing before passing the path to the kernel. But, for consistency, one would have to resolve symlinks before comparing paths in Windows as well.

I think if you need this in-depth comparison, it's better to call resolve() manually when paths aren't superficially equal.
msg382026 - (view) Author: Austin Scola (ascola) Date: 2020-11-28 22:42
Okay, thank you for the explanation Eryk. It makes sense to me now why __eq__ doesn't attempt to compare something other than just the parts of the path.
History
Date User Action Args
2020-11-29 01:34:44eryksunsetresolution: rejected
type: behavior -> enhancement
2020-11-28 22:42:03ascolasetstatus: open -> closed

messages: + msg382026
stage: resolved
2020-11-28 22:02:08eryksunsetnosy: + eryksun
messages: + msg382019
2020-11-28 20:38:39ascolacreate