Coverage for src/extratools_core/typing.py: 69%

16 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-06 23:52 -0700

1from abc import abstractmethod 

2from typing import Protocol, Self, runtime_checkable 

3 

4 

5@runtime_checkable 

6class Comparable(Protocol): # noqa: PLW1641 

7 """ 

8 Based on https://github.com/python/typing/issues/59 

9 """ 

10 

11 @abstractmethod 

12 def __eq__(self, other: object) -> bool: 

13 ... 

14 

15 @abstractmethod 

16 def __lt__(self, other: Self) -> bool: 

17 ... 

18 

19 def __gt__(self, other: Self) -> bool: 

20 return (not self < other) and self != other 

21 

22 def __le__(self, other: Self) -> bool: 

23 return self < other or self == other 

24 

25 def __ge__(self, other: Self) -> bool: 

26 return (not self < other)