Skip to content

Commit

Permalink
lib: Replaced __cmp__ method with compensating methods for Python3 fu…
Browse files Browse the repository at this point in the history
…nctionality (#4684)

* updated cmp

* updated gt

* removed cmp
  • Loading branch information
arohanajit authored Dec 27, 2024
1 parent a13efe9 commit 306d596
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 0 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ per-file-ignores =
gui/wxpython/timeline/g.gui.timeline.py: E501
# Generated file
gui/wxpython/menustrings.py: E501
# F821 undefined name 'cmp'
# https://github.com/OSGeo/grass/issues/1809
python/grass/pydispatch/saferef.py: F821
# C wrappers call libgis.G_gisinit before importing other modules.
# TODO: Is this really needed?
python/grass/pygrass/vector/__init__.py: E402
Expand Down
17 changes: 13 additions & 4 deletions python/grass/pydispatch/saferef.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,20 @@ def __nonzero__(self):

__bool__ = __nonzero__

def __cmp__(self, other):
"""Compare with another reference"""
def __eq__(self, other):
if not isinstance(other, self.__class__):
return cmp(self.__class__, type(other))
return cmp(self.key, other.key)
return False
return self.key == other.key

def __lt__(self, other):
if not isinstance(other, self.__class__):
return self.__class__.__name__ < other.__class__.__name__
return self.key < other.key

def __gt__(self, other):
if not isinstance(other, self.__class__):
return self.__class__.__name__ > other.__class__.__name__
return self.key > other.key

def __call__(self):
"""Return a strong reference to the bound method
Expand Down

0 comments on commit 306d596

Please sign in to comment.