Path: blob/master/venv/Lib/site-packages/pip/_internal/utils/models.py
811 views
"""Utilities for defining models1"""2# The following comment should be removed at some point in the future.3# mypy: disallow-untyped-defs=False45import operator678class KeyBasedCompareMixin(object):9"""Provides comparison capabilities that is based on a key10"""1112def __init__(self, key, defining_class):13self._compare_key = key14self._defining_class = defining_class1516def __hash__(self):17return hash(self._compare_key)1819def __lt__(self, other):20return self._compare(other, operator.__lt__)2122def __le__(self, other):23return self._compare(other, operator.__le__)2425def __gt__(self, other):26return self._compare(other, operator.__gt__)2728def __ge__(self, other):29return self._compare(other, operator.__ge__)3031def __eq__(self, other):32return self._compare(other, operator.__eq__)3334def __ne__(self, other):35return self._compare(other, operator.__ne__)3637def _compare(self, other, method):38if not isinstance(other, self._defining_class):39return NotImplemented4041return method(self._compare_key, other._compare_key)424344