In builtins.pyi there is:
def __eq__(self, __o: object) -> bool: ...
def __ne__(self, __o: object) -> bool: ...
But I think that both of these methods should return object. I believe that they eventually get called in CPython by tp_richcompare which doesn't necessarily return bool (https://github.com/python/cpython/blob/1626bf4ac7aef1244e6f886e63a31f7ed65fbd10/Objects/object.c#L655).
There is Python code that takes advantage of this to override == to return something other than a bool (e.g., numpy arrays). Type checking code like that against the typeshed type stubs leads to incompatible overrides (e.g., numpy array is not a subtype of bool).
Should these methods be annotated as returning object?
In
builtins.pyithere is:But I think that both of these methods should return
object. I believe that they eventually get called in CPython bytp_richcomparewhich doesn't necessarily returnbool(https://github.com/python/cpython/blob/1626bf4ac7aef1244e6f886e63a31f7ed65fbd10/Objects/object.c#L655).There is Python code that takes advantage of this to override
==to return something other than a bool (e.g., numpy arrays). Type checking code like that against the typeshed type stubs leads to incompatible overrides (e.g., numpy array is not a subtype ofbool).Should these methods be annotated as returning
object?