Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hhhrrrttt222111
GitHub Repository: hhhrrrttt222111/Dorkify
Path: blob/master/venv/Lib/site-packages/pip/_internal/utils/models.py
811 views
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)
43
44