Fix EqualityComparable.__eq__ typing

This commit is contained in:
Gnome! 2021-07-29 00:55:19 +01:00 committed by GitHub
parent dd8168f902
commit 67026809a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,24 +22,20 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
""" """
from typing import TypeVar
__all__ = ( __all__ = (
'EqualityComparable', 'EqualityComparable',
'Hashable', 'Hashable',
) )
E = TypeVar('E', bound='EqualityComparable')
class EqualityComparable: class EqualityComparable:
__slots__ = () __slots__ = ()
id: int id: int
def __eq__(self: E, other: E) -> bool: def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__) and other.id == self.id return isinstance(other, self.__class__) and other.id == self.id
def __ne__(self: E, other: E) -> bool: def __ne__(self, other: object) -> bool:
if isinstance(other, self.__class__): if isinstance(other, self.__class__):
return other.id != self.id return other.id != self.id
return True return True