-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
A NummedObj instance cannot be compared for equality or non-equality against arbitrary objects:
>>> from pyutil.nummedobj import NummedObj
>>> class X(NummedObj): pass
...
>>> x = X()
>>> x == 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/nix/store/9ms6vnn4iakl4aix85ygc7ana5kshhj1-python3-3.9.6-env/lib/python3.9/site-packages/pyutil/nummedobj.py", line 41, in __eq__
return (self._objid, self._classname,) == (other._objid, other._classname,)
AttributeError: 'int' object has no attribute '_objid'
>>> x != 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/nix/store/9ms6vnn4iakl4aix85ygc7ana5kshhj1-python3-3.9.6-env/lib/python3.9/site-packages/pyutil/nummedobj.py", line 44, in __ne__
return (self._objid, self._classname,) != (other._objid, other._classname,)
AttributeError: 'int' object has no attribute '_objid'
>>>
But the typical assumption would be that since x is not very similar to 1, x == 1 would evaluate to False and x != 1 would evaluate to True.
This broken assumption causes problems in a number of places since it means NummedObj instances don't really implement the equality protocol, only a subset of it.
Metadata
Metadata
Assignees
Labels
No labels