Sort Pathclass by normcase instead of absolute path.

This commit is contained in:
Ethan Dalool 2020-09-02 08:52:13 -07:00
parent 53528741b2
commit 27291df9ad

View file

@ -94,13 +94,17 @@ class Path:
def __eq__(self, other): def __eq__(self, other):
if not hasattr(other, 'absolute_path'): if not hasattr(other, 'absolute_path'):
return False return False
# Compare by normcase so that Windows's case-insensitive filenames
# behave correctly.
return self.normcase == other.normcase return self.normcase == other.normcase
def __hash__(self): def __hash__(self):
return hash(self.normcase) return hash(self.normcase)
def __lt__(self, other): def __lt__(self, other):
return self.absolute_path < other.absolute_path # Sort by normcase so that Windows's case-insensitive filenames sort
# alphabetically regardless of case.
return self.normcase < other.normcase
def __repr__(self): def __repr__(self):
return '{c}({path})'.format(c=self.__class__.__name__, path=repr(self.absolute_path)) return '{c}({path})'.format(c=self.__class__.__name__, path=repr(self.absolute_path))