Adds a __repr__ to graph.
[pyutils.git] / src / pyutils / typez / typing.py
1 #!/usr/bin/env python3
2
3 # © Copyright 2021-2023, Scott Gasch
4
5 """My type hints."""
6
7 from abc import abstractmethod
8 from typing import Any, Protocol, Union
9
10 Numeric = Union[int, float]
11
12
13 class Comparable(Protocol):
14     """Anything that implements basic comparison methods such that it
15     can be compared to other instances of the same type.
16
17     Check out :meth:`functools.total_ordering`
18     (https://docs.python.org/3/library/functools.html#functools.total_ordering)
19     for an easy way to make your type comparable.
20     """
21
22     @abstractmethod
23     def __lt__(self, other: Any) -> bool:
24         ...
25
26     @abstractmethod
27     def __le__(self, other: Any) -> bool:
28         ...
29
30     @abstractmethod
31     def __eq__(self, other: Any) -> bool:
32         ...
33
34
35 class Closable(Protocol):
36     """Something that can be closed."""
37
38     def close(self) -> None:
39         ...
40
41
42 class Cloneable(Protocol):
43     """Something that can be cloned."""
44
45     def clone(self) -> None:
46         ...
47
48
49 class Runnable(Protocol):
50     """Something that can be run."""
51
52     def run(self) -> None:
53         ...