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

17 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-04 05:56 -0700

1from __future__ import annotations 

2 

3from abc import abstractmethod 

4from typing import Protocol, runtime_checkable 

5 

6 

7@runtime_checkable 

8class Comparable(Protocol): # noqa: PLW1641 

9 """ 

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

11 """ 

12 

13 @abstractmethod 

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

15 ... 

16 

17 @abstractmethod 

18 def __lt__(self, other: Comparable) -> bool: 

19 ... 

20 

21 def __gt__(self, other: Comparable) -> bool: 

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

23 

24 def __le__(self, other: Comparable) -> bool: 

25 return self < other or self == other 

26 

27 def __ge__(self, other: Comparable) -> bool: 

28 return (not self < other)