Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/pip/_internal/utils/models.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 """Utilities for defining models | |
2 """ | |
3 # The following comment should be removed at some point in the future. | |
4 # mypy: disallow-untyped-defs=False | |
5 | |
6 import operator | |
7 | |
8 | |
9 class KeyBasedCompareMixin: | |
10 """Provides comparison capabilities that is based on a key | |
11 """ | |
12 | |
13 __slots__ = ['_compare_key', '_defining_class'] | |
14 | |
15 def __init__(self, key, defining_class): | |
16 self._compare_key = key | |
17 self._defining_class = defining_class | |
18 | |
19 def __hash__(self): | |
20 return hash(self._compare_key) | |
21 | |
22 def __lt__(self, other): | |
23 return self._compare(other, operator.__lt__) | |
24 | |
25 def __le__(self, other): | |
26 return self._compare(other, operator.__le__) | |
27 | |
28 def __gt__(self, other): | |
29 return self._compare(other, operator.__gt__) | |
30 | |
31 def __ge__(self, other): | |
32 return self._compare(other, operator.__ge__) | |
33 | |
34 def __eq__(self, other): | |
35 return self._compare(other, operator.__eq__) | |
36 | |
37 def _compare(self, other, method): | |
38 if not isinstance(other, self._defining_class): | |
39 return NotImplemented | |
40 | |
41 return method(self._compare_key, other._compare_key) |