| [case testTotalOrderingEqLt] |
| from functools import total_ordering |
| |
| @total_ordering |
| class Ord: |
| def __eq__(self, other: object) -> bool: |
| return False |
| |
| def __lt__(self, other: "Ord") -> bool: |
| return False |
| |
| reveal_type(Ord() < Ord()) # N: Revealed type is "builtins.bool" |
| reveal_type(Ord() <= Ord()) # N: Revealed type is "builtins.bool" |
| reveal_type(Ord() == Ord()) # N: Revealed type is "builtins.bool" |
| reveal_type(Ord() > Ord()) # N: Revealed type is "builtins.bool" |
| reveal_type(Ord() >= Ord()) # N: Revealed type is "builtins.bool" |
| |
| Ord() < 1 # E: Unsupported operand types for < ("Ord" and "int") |
| Ord() <= 1 # E: Unsupported operand types for <= ("Ord" and "int") |
| Ord() == 1 |
| Ord() > 1 # E: Unsupported operand types for > ("Ord" and "int") |
| Ord() >= 1 # E: Unsupported operand types for >= ("Ord" and "int") |
| [builtins fixtures/dict.pyi] |
| |
| [case testTotalOrderingLambda] |
| from functools import total_ordering |
| from typing import Any, Callable, ClassVar |
| |
| @total_ordering |
| class Ord: |
| __eq__: Callable[[Any, object], bool] = lambda self, other: False |
| __lt__: Callable[[Any, "Ord"], bool] = lambda self, other: False |
| |
| reveal_type(Ord() < Ord()) # N: Revealed type is "builtins.bool" |
| reveal_type(Ord() <= Ord()) # N: Revealed type is "builtins.bool" |
| reveal_type(Ord() == Ord()) # N: Revealed type is "builtins.bool" |
| reveal_type(Ord() > Ord()) # N: Revealed type is "builtins.bool" |
| reveal_type(Ord() >= Ord()) # N: Revealed type is "builtins.bool" |
| |
| Ord() < 1 # E: Argument 1 has incompatible type "int"; expected "Ord" |
| Ord() <= 1 # E: Unsupported operand types for <= ("Ord" and "int") |
| Ord() == 1 |
| Ord() > 1 # E: Unsupported operand types for > ("Ord" and "int") |
| Ord() >= 1 # E: Unsupported operand types for >= ("Ord" and "int") |
| [builtins fixtures/dict.pyi] |
| |
| [case testTotalOrderingNonCallable] |
| from functools import total_ordering |
| |
| @total_ordering |
| class Ord(object): |
| def __eq__(self, other: object) -> bool: |
| return False |
| |
| __lt__ = 5 |
| |
| Ord() <= Ord() # E: Unsupported left operand type for <= ("Ord") |
| Ord() > Ord() # E: "int" not callable |
| Ord() >= Ord() # E: Unsupported left operand type for >= ("Ord") |
| [builtins fixtures/dict.pyi] |
| |
| [case testTotalOrderingReturnNotBool] |
| from functools import total_ordering |
| |
| @total_ordering |
| class Ord: |
| def __eq__(self, other: object) -> bool: |
| return False |
| |
| def __lt__(self, other: "Ord") -> str: |
| return "blah" |
| |
| reveal_type(Ord() < Ord()) # N: Revealed type is "builtins.str" |
| reveal_type(Ord() <= Ord()) # N: Revealed type is "Any" |
| reveal_type(Ord() == Ord()) # N: Revealed type is "builtins.bool" |
| reveal_type(Ord() > Ord()) # N: Revealed type is "Any" |
| reveal_type(Ord() >= Ord()) # N: Revealed type is "Any" |
| [builtins fixtures/dict.pyi] |
| |
| [case testTotalOrderingAllowsAny] |
| from functools import total_ordering |
| |
| @total_ordering |
| class Ord: |
| def __eq__(self, other): |
| return False |
| |
| def __gt__(self, other): |
| return False |
| |
| reveal_type(Ord() < Ord()) # N: Revealed type is "Any" |
| Ord() <= Ord() # E: Unsupported left operand type for <= ("Ord") |
| reveal_type(Ord() == Ord()) # N: Revealed type is "Any" |
| reveal_type(Ord() > Ord()) # N: Revealed type is "Any" |
| Ord() >= Ord() # E: Unsupported left operand type for >= ("Ord") |
| |
| Ord() < 1 # E: Unsupported left operand type for < ("Ord") |
| Ord() <= 1 # E: Unsupported left operand type for <= ("Ord") |
| Ord() == 1 |
| Ord() > 1 |
| Ord() >= 1 # E: Unsupported left operand type for >= ("Ord") |
| [builtins fixtures/dict.pyi] |
| |
| [case testCachedProperty] |
| # flags: --python-version 3.8 |
| from functools import cached_property |
| class Parent: |
| @property |
| def f(self) -> str: pass |
| class Child(Parent): |
| @cached_property |
| def f(self) -> str: pass |
| @cached_property |
| def g(self) -> int: pass |
| @cached_property # E: Too many arguments for property |
| def h(self, arg) -> int: pass |
| reveal_type(Parent().f) # N: Revealed type is "builtins.str" |
| reveal_type(Child().f) # N: Revealed type is "builtins.str" |
| reveal_type(Child().g) # N: Revealed type is "builtins.int" |
| Child().f = "Hello World" |
| Child().g = "invalid" # E: Incompatible types in assignment (expression has type "str", variable has type "int") |
| [file functools.pyi] |
| import sys |
| from typing import TypeVar, Generic |
| _T = TypeVar('_T') |
| class cached_property(Generic[_T]): ... |
| [builtins fixtures/property.pyi] |
| |
| [case testTotalOrderingWithForwardReference] |
| from typing import Generic, Any, TypeVar |
| import functools |
| |
| T = TypeVar("T", bound="C") |
| |
| @functools.total_ordering |
| class D(Generic[T]): |
| def __lt__(self, other: Any) -> bool: |
| ... |
| |
| class C: |
| pass |
| |
| def f(d: D[C]) -> None: |
| reveal_type(d.__gt__) # N: Revealed type is "def (other: Any) -> builtins.bool" |
| |
| d: D[int] # E: Type argument "int" of "D" must be a subtype of "C" |
| [builtins fixtures/dict.pyi] |