Path: blob/main/test/lib/python3.9/site-packages/pip/_internal/utils/models.py
4804 views
"""Utilities for defining models1"""23import operator4from typing import Any, Callable, Type567class KeyBasedCompareMixin:8"""Provides comparison capabilities that is based on a key"""910__slots__ = ["_compare_key", "_defining_class"]1112def __init__(self, key: Any, defining_class: Type["KeyBasedCompareMixin"]) -> None:13self._compare_key = key14self._defining_class = defining_class1516def __hash__(self) -> int:17return hash(self._compare_key)1819def __lt__(self, other: Any) -> bool:20return self._compare(other, operator.__lt__)2122def __le__(self, other: Any) -> bool:23return self._compare(other, operator.__le__)2425def __gt__(self, other: Any) -> bool:26return self._compare(other, operator.__gt__)2728def __ge__(self, other: Any) -> bool:29return self._compare(other, operator.__ge__)3031def __eq__(self, other: Any) -> bool:32return self._compare(other, operator.__eq__)3334def _compare(self, other: Any, method: Callable[[Any, Any], bool]) -> bool:35if not isinstance(other, self._defining_class):36return NotImplemented3738return method(self._compare_key, other._compare_key)394041