Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_internal/utils/models.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:47:31 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9e54283cc701 |
---|---|
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(object): | |
10 """Provides comparison capabilities that is based on a key | |
11 """ | |
12 | |
13 def __init__(self, key, defining_class): | |
14 self._compare_key = key | |
15 self._defining_class = defining_class | |
16 | |
17 def __hash__(self): | |
18 return hash(self._compare_key) | |
19 | |
20 def __lt__(self, other): | |
21 return self._compare(other, operator.__lt__) | |
22 | |
23 def __le__(self, other): | |
24 return self._compare(other, operator.__le__) | |
25 | |
26 def __gt__(self, other): | |
27 return self._compare(other, operator.__gt__) | |
28 | |
29 def __ge__(self, other): | |
30 return self._compare(other, operator.__ge__) | |
31 | |
32 def __eq__(self, other): | |
33 return self._compare(other, operator.__eq__) | |
34 | |
35 def __ne__(self, other): | |
36 return self._compare(other, operator.__ne__) | |
37 | |
38 def _compare(self, other, method): | |
39 if not isinstance(other, self._defining_class): | |
40 return NotImplemented | |
41 | |
42 return method(self._compare_key, other._compare_key) |