lib: Fix safeRef regression after removing __cmp__
in #4684
#4896
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After stepping through a lot with PDB, I suggest this to fix the hang described in #4684 (comment) and #4684 (comment)
It isn't a question of missing
__le__
,__ge__
,__ne__
as the replacement of__cmp__
with all rich comparisons. They don't get called. The current (before #4684)__cmp__
method isn't called at all in Python 3 (breakpoint isn't hit, while other do).In #4684, the
__eq__
method gets called by thelist.index
from the receivers.index(receiver) in here:grass/python/grass/pydispatch/dispatcher.py
Lines 448 to 478 in 7f1934f
Looking at the locals() available in debugging at various stack levels, I see no real difference between having the
__eq__
method after #4684, or removing it completly (by memory of what I saw multiple dozens of times per code-change though, so I might be wrong). However, without any extra method, it works, on Linux (ubuntu 22.04 container on WSL) and on windows (editing the saferef.py file in an OSGeo4W grass-dev build 432). I cannot test on macOS, but I suppose it is the same.This PR effectively has the same behavior as before #4684 for python 3, as that method didn't get called.
From what I searched, it really should have only been called, in python 2, if a list was sorted. I didn't find any other ways the methods in saferef could get triggered.
I consider this change safe.
Additionnaly, in my first attempts to debug this, I also tried raising warnings (similar to DeprecationWarning), with PYTHONWARNINGS=always env var on all methods in saferef, and other methos appeared, but never
__cmp__
, or the others added in #4684, of course,__eq__
was called, as it was the problematic part