PRE-PEP: new Path class; mutability, __hash__, __eq__, __cmp__

Christoph Becker-Freyseng webmaster at beyond-thoughts.com
Fri Jan 9 12:06:03 EST 2004


Bernhard Herzog wrote:
> Christoph Becker-Freyseng <webmaster at beyond-thoughts.com> writes:
> 
> 
>>So for __eq__ it follows naturaly
>>def __eq__(self, other):
>>	FIXME: isinstance checking
>>	return (str(self.normalized()) == str(other.normalized()))
>>It cares about nonexistent paths, too. (The samefile-solution won't --- 
>>we might code a special case for it ...)
> 
> 
> What exactly does normalized() do?  If it's equivalent to
> os.path.normpath, then p1 == p2 might be true even though they refer to
IMO yes.
> different files (on posix, a/../b is not necessarily the same file as
> b).  OTOH, if it also called os.path.realpath too to take symlinks into
> account, __eq__ would depend on the state of the filesystem which is
> also bad.
> 
> IMO __eq__ should simply compare the strings without any modification.
> If you want to compare normalized paths you should have to normalize
> them explicitly.
I agree with that. While it would be nice if __eq__ could match such 
things it is ambiguous.
So better let __eq__ be a bit strict than faulty.



Christoph Becker-Freyseng





More information about the Python-list mailing list