"""Utilities for defining models
"""
import operator
from typing import Any, Callable, Type
class KeyBasedCompareMixin:
"""Provides comparison capabilities that is based on a key"""
__slots__ = ["_compare_key", "_defining_class"]
def __init__(self, key: Any, defining_class: Type["KeyBasedCompareMixin"]) -> None:
self._compare_key = key
self._defining_class = defining_class
def __hash__(self) -> int:
return hash(self._compare_key)
def __lt__(self, other: Any) -> bool:
return self._compare(other, operator.__lt__)
def __le__(self, other: Any) -> bool:
return self._compare(other, operator.__le__)
def __gt__(self, other: Any) -> bool:
return self._compare(other, operator.__gt__)
def __ge__(self, other: Any) -> bool:
return self._compare(other, operator.__ge__)
def __eq__(self, other: Any) -> bool:
return self._compare(other, operator.__eq__)
def _compare(self, other: Any, method: Callable[[Any, Any], bool]) -> bool:
if not isinstance(other, self._defining_class):
return NotImplemented
return method(self._compare_key, other._compare_key)
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| __init__.py | File | 0 B | 0644 |
|
| _jaraco_text.py | File | 3.27 KB | 0644 |
|
| _log.py | File | 1015 B | 0644 |
|
| appdirs.py | File | 1.63 KB | 0644 |
|
| compat.py | File | 1.84 KB | 0644 |
|
| compatibility_tags.py | File | 5.25 KB | 0644 |
|
| datetime.py | File | 242 B | 0644 |
|
| deprecation.py | File | 3.54 KB | 0644 |
|
| direct_url_helpers.py | File | 3.13 KB | 0644 |
|
| egg_link.py | File | 2.07 KB | 0644 |
|
| encoding.py | File | 1.14 KB | 0644 |
|
| entrypoints.py | File | 3.07 KB | 0644 |
|
| filesystem.py | File | 5 KB | 0644 |
|
| filetypes.py | File | 716 B | 0644 |
|
| glibc.py | File | 3.04 KB | 0644 |
|
| hashes.py | File | 5 KB | 0644 |
|
| logging.py | File | 11.33 KB | 0644 |
|
| misc.py | File | 23.18 KB | 0644 |
|
| models.py | File | 1.17 KB | 0644 |
|
| packaging.py | File | 2.06 KB | 0644 |
|
| setuptools_build.py | File | 4.33 KB | 0644 |
|
| subprocess.py | File | 8.99 KB | 0644 |
|
| temp_dir.py | File | 9.09 KB | 0644 |
|
| unpacking.py | File | 8.61 KB | 0644 |
|
| urls.py | File | 1.72 KB | 0644 |
|
| virtualenv.py | File | 3.38 KB | 0644 |
|
| wheel.py | File | 4.44 KB | 0644 |
|