Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: Updated __cmp__ method for Python3 functionality #4684

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ per-file-ignores =
gui/wxpython/rlisetup/wizard.py: E722
# 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
21 changes: 19 additions & 2 deletions python/grass/pydispatch/saferef.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,25 @@ def __nonzero__(self):
def __cmp__(self, other):
"""Compare with another reference"""
if not isinstance(other, self.__class__):
return cmp(self.__class__, type(other))
return cmp(self.key, other.key)
return (self.__class__.__name__ > other.__class__.__name__) - (
self.__class__.__name__ < other.__class__.__name__
)
return (self.key > other.key) - (self.key < other.key)

def __eq__(self, other):
if not isinstance(other, self.__class__):
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
Loading