1
1
import sys
2
- from _typeshed import SupportsAnyComparison
3
2
from
8000
typing import (
4
3
Any ,
5
4
AnyStr ,
@@ -25,6 +24,24 @@ _K = TypeVar("_K")
25
24
_V = TypeVar ("_V" )
26
25
_P = ParamSpec ("_P" )
27
26
27
+ # The following protocols return "Any" instead of bool, since the comparison
28
+ # operators can be overloaded to return an arbitrary object. For example,
29
+ # the numpy.array comparison dunders return another numpy.array.
30
+
31
+ class _SupportsDunderLT (Protocol ):
32
+ def __lt__ (self , __other : Any ) -> Any : ...
33
+
34
+ class _SupportsDunderGT (Protocol ):
35
+ def __gt__ (self , __other : Any ) -> Any : ...
36
+
37
+ class _SupportsDunderLE (Protocol ):
38
+ def __le__ (self , __other : Any ) -> Any : ...
39
+
40
+ class _SupportsDunderGE (Protocol ):
41
+ def __ge__ (self , __other : Any ) -> Any : ...
42
+
43
+ _SupportsComparison = _SupportsDunderLE | _SupportsDunderGE | _SupportsDunderGT | _SupportsDunderLT
44
+
28
45
class _SupportsInversion (Protocol [_T_co ]):
29
46
def __invert__ (self ) -> _T_co : ...
30
47
@@ -35,12 +52,12 @@ class _SupportsPos(Protocol[_T_co]):
35
52
def __pos__ (self ) -> _T_co : ...
36
53
37
54
# All four comparison functions must have the same signature, or we get false-positive errors
38
- def lt (__a : SupportsAnyComparison , __b : SupportsAnyComparison ) -> Any : ...
39
- def le (__a : SupportsAnyComparison , __b : SupportsAnyComparison ) -> Any : ...
55
+ def lt (__a : _SupportsComparison , __b : _SupportsComparison ) -> Any : ...
56
+ def le (__a : _SupportsComparison , __b : _SupportsComparison ) -> Any : ...
40
57
def eq (__a : object , __b : object ) -> Any : ...
41
58
def ne (__a : object , __b : object ) -> Any : ...
42
- def ge (__a : SupportsAnyComparison , __b : SupportsAnyComparison ) -> Any : ...
43
- def gt (__a : SupportsAnyComparison , __b : SupportsAnyComparison ) -> Any : ...
59
+ def ge (__a : _SupportsComparison , __b : _SupportsComparison ) -> Any : ...
60
+ def gt (__a : _SupportsComparison , __b : _SupportsComparison ) -> Any : ...
44
61
def not_ (__a : object ) -> bool : ...
45
62
def truth (__a : object ) -> bool : ...
46
63
def is_ (__a : object , __b : object ) -> bool : ...
0 commit comments