From 6d8b50c5eb558844f8abc2a7784a8887b8c2eee5 Mon Sep 17 00:00:00 2001 From: Paul Fisher Date: Wed, 15 Feb 2023 14:57:26 -0500 Subject: [PATCH] Remove the `Comparable` protocol. We don't use it anymore, and it is not useful for static analysis (you only need to implement a subset of the methods to support all comparisons) nor at runtime (every object implements all of the `__xx__` methods, but most return `NotImplemented`, meaning that `isinstance(anything, Comparable)` was always true even for things that were not comparable, like regular old `object()`. --- python-spec/src/somacore/types.py | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/python-spec/src/somacore/types.py b/python-spec/src/somacore/types.py index edc4639b..747b7bb1 100644 --- a/python-spec/src/somacore/types.py +++ b/python-spec/src/somacore/types.py @@ -2,7 +2,7 @@ import sys from typing import Any, NoReturn, Optional, Type, TypeVar, Sequence, TYPE_CHECKING -from typing_extensions import Protocol, Self, TypeGuard +from typing_extensions import Protocol, TypeGuard def is_nonstringy_sequence(it: Any) -> TypeGuard[Sequence]: @@ -15,28 +15,6 @@ def is_nonstringy_sequence(it: Any) -> TypeGuard[Sequence]: return not isinstance(it, (str, bytes)) and isinstance(it, Sequence) -class Comparable(Protocol): - """Objects that can be ``<``/``==``/``>``'d.""" - - def __lt__(self, __other: Self) -> bool: - ... - - def __le__(self, __other: Self) -> bool: - ... - - def __eq__(self, __other: object) -> bool: - ... - - def __ne__(self, __other: object) -> bool: - ... - - def __ge__(self, __other: Self) -> bool: - ... - - def __gt__(self, __other: Self) -> bool: - ... - - _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True)