[Python-Dev] Path PEP: some comments (equality)

Chris AtLee chris at atlee.ca
Thu Feb 23 22:01:08 CET 2006


On 2/20/06, Mark Mc Mahon <mark.m.mcmahon at gmail.com> wrote:
> Hi,
>
> It seems that the Path module as currently defined leaves equality
> testing up to the underlying string comparison. My guess is that this
> is fine for Unix (maybe not even) but it is a bit lacking for Windows.
>
> Should the path class implement an __eq__ method that might do some of
> the following things:
>  - Get the absolute path of both self and the other path
>  - normcase both
>  - now see if they are equal
>
> This would make working with paths much easier for keys of a
> dictionary on windows. (I frequently use a case insensitive string
> class for paths if I need them to be keys of a dict.)

The PEP specifies path.samefile(), which is useful in the case of
files that actually exist, but pretty much useless for comparing paths
that don't exist on the local machine.

I think leaving __eq__ as the default string comparison is best.  But
what about providing an alternate platform-specific equality test?

def isequal(self, other, platform="native"):
    """Return True if self is equivalent to other using platform's
path comparison rules.  platform can be one of "native", "posix",
"windows", "mac"."""

This could do some combination of os.path.normpath() and
os.path.normcase() depending on the platform.  The docs for
os.path.normpath() say that it may change the meaning of the path if
it contains symlinks...it's not clear to me how though.

Cheers,
Chris


More information about the Python-Dev mailing list