cmp3 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cmp3-0.2.0/src/cmp3.egg-info → cmp3-0.3.0}/PKG-INFO +1 -1
- {cmp3-0.2.0 → cmp3-0.3.0}/pyproject.toml +1 -1
- cmp3-0.3.0/src/cmp3/core/__init__.py +70 -0
- {cmp3-0.2.0 → cmp3-0.3.0/src/cmp3.egg-info}/PKG-INFO +1 -1
- cmp3-0.2.0/src/cmp3/core/__init__.py +0 -60
- {cmp3-0.2.0 → cmp3-0.3.0}/LICENSE.txt +0 -0
- {cmp3-0.2.0 → cmp3-0.3.0}/MANIFEST.in +0 -0
- {cmp3-0.2.0 → cmp3-0.3.0}/README.rst +0 -0
- {cmp3-0.2.0 → cmp3-0.3.0}/setup.cfg +0 -0
- {cmp3-0.2.0 → cmp3-0.3.0}/src/cmp3/__init__.py +0 -0
- {cmp3-0.2.0 → cmp3-0.3.0}/src/cmp3/tests/__init__.py +0 -0
- {cmp3-0.2.0 → cmp3-0.3.0}/src/cmp3/tests/test_1984.py +0 -0
- {cmp3-0.2.0 → cmp3-0.3.0}/src/cmp3.egg-info/SOURCES.txt +0 -0
- {cmp3-0.2.0 → cmp3-0.3.0}/src/cmp3.egg-info/dependency_links.txt +0 -0
- {cmp3-0.2.0 → cmp3-0.3.0}/src/cmp3.egg-info/requires.txt +0 -0
- {cmp3-0.2.0 → cmp3-0.3.0}/src/cmp3.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from functools import partial
|
|
3
|
+
from typing import *
|
|
4
|
+
|
|
5
|
+
import setdoc
|
|
6
|
+
|
|
7
|
+
__all__ = ["Comparable", "comparable", "update_rich_cmp"]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def comparable(*, overwrites: Any = False) -> partial:
|
|
11
|
+
"This function returns a decorator."
|
|
12
|
+
return partial(update_rich_cmp, overwrites=overwrites)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def update_rich_cmp(cls: type, /, *, overwrites: Any = False) -> type:
|
|
16
|
+
@setdoc.basic
|
|
17
|
+
def __eq__(self: Self, other: Any) -> Any:
|
|
18
|
+
return self.__cmp__(other) == 0
|
|
19
|
+
|
|
20
|
+
@setdoc.basic
|
|
21
|
+
def __ge__(self: Self, other: Any) -> Any:
|
|
22
|
+
return self.__cmp__(other) >= 0
|
|
23
|
+
|
|
24
|
+
@setdoc.basic
|
|
25
|
+
def __gt__(self: Self, other: Any) -> Any:
|
|
26
|
+
return self.__cmp__(other) > 0
|
|
27
|
+
|
|
28
|
+
@setdoc.basic
|
|
29
|
+
def __le__(self: Self, other: Any) -> Any:
|
|
30
|
+
return self.__cmp__(other) <= 0
|
|
31
|
+
|
|
32
|
+
@setdoc.basic
|
|
33
|
+
def __lt__(self: Self, other: Any) -> Any:
|
|
34
|
+
return self.__cmp__(other) < 0
|
|
35
|
+
|
|
36
|
+
@setdoc.basic
|
|
37
|
+
def __ne__(self: Self, other: Any) -> Any:
|
|
38
|
+
return self.__cmp__(other) != 0
|
|
39
|
+
|
|
40
|
+
func: Callable
|
|
41
|
+
funcs: list[Callable]
|
|
42
|
+
funcs = [
|
|
43
|
+
__eq__,
|
|
44
|
+
__ge__,
|
|
45
|
+
__gt__,
|
|
46
|
+
__le__,
|
|
47
|
+
__lt__,
|
|
48
|
+
__ne__,
|
|
49
|
+
]
|
|
50
|
+
for func in funcs:
|
|
51
|
+
if hasattr(cls, func.__name__) and not overwrites:
|
|
52
|
+
continue
|
|
53
|
+
setattr(cls, func.__name__, func)
|
|
54
|
+
try:
|
|
55
|
+
func.__module__ = cls.__module__
|
|
56
|
+
except AttributeError:
|
|
57
|
+
pass
|
|
58
|
+
try:
|
|
59
|
+
func.__qualname__ = cls.__qualname__
|
|
60
|
+
except AttributeError:
|
|
61
|
+
pass
|
|
62
|
+
return cls
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@comparable()
|
|
66
|
+
class Comparable(ABC):
|
|
67
|
+
__slots__ = ()
|
|
68
|
+
|
|
69
|
+
@abstractmethod
|
|
70
|
+
def __cmp__(self: Self, other: Any) -> Any: ...
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
|
-
from functools import partial
|
|
3
|
-
from typing import *
|
|
4
|
-
|
|
5
|
-
import setdoc
|
|
6
|
-
|
|
7
|
-
__all__ = ["Comparable", "comparable"]
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def comparable(*, overwrite: Any = False) -> type:
|
|
11
|
-
return partial(update, overwrite=overwrite)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def update(cls: type, /, *, overwrite: Any = False) -> type:
|
|
15
|
-
@setdoc.basic
|
|
16
|
-
def __eq__(self: Self, other: Any) -> bool:
|
|
17
|
-
return self.__cmp__(other) == 0
|
|
18
|
-
|
|
19
|
-
@setdoc.basic
|
|
20
|
-
def __ge__(self: Self, other: Any) -> bool:
|
|
21
|
-
return self.__cmp__(other) >= 0
|
|
22
|
-
|
|
23
|
-
@setdoc.basic
|
|
24
|
-
def __gt__(self: Self, other: Any) -> bool:
|
|
25
|
-
return self.__cmp__(other) > 0
|
|
26
|
-
|
|
27
|
-
@setdoc.basic
|
|
28
|
-
def __le__(self: Self, other: Any) -> bool:
|
|
29
|
-
return self.__cmp__(other) <= 0
|
|
30
|
-
|
|
31
|
-
@setdoc.basic
|
|
32
|
-
def __lt__(self: Self, other: Any) -> bool:
|
|
33
|
-
return self.__cmp__(other) < 0
|
|
34
|
-
|
|
35
|
-
@setdoc.basic
|
|
36
|
-
def __ne__(self: Self, other: Any) -> bool:
|
|
37
|
-
return self.__cmp__(other) != 0
|
|
38
|
-
|
|
39
|
-
func: Callable
|
|
40
|
-
funcs: list[Callable]
|
|
41
|
-
funcs = [
|
|
42
|
-
__eq__,
|
|
43
|
-
__ge__,
|
|
44
|
-
__gt__,
|
|
45
|
-
__le__,
|
|
46
|
-
__lt__,
|
|
47
|
-
__ne__,
|
|
48
|
-
]
|
|
49
|
-
for func in funcs:
|
|
50
|
-
if overwrite or not hasattr(cls, func.__name__):
|
|
51
|
-
setattr(cls, func.__name__, func)
|
|
52
|
-
return cls
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
@comparable()
|
|
56
|
-
class Comparable(ABC):
|
|
57
|
-
__slots__ = ()
|
|
58
|
-
|
|
59
|
-
@abstractmethod
|
|
60
|
-
def __cmp__(self: Self, other: Any) -> Any: ...
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|