|
4 | 4 |
|
5 | 5 |
|
6 | 6 | class ComparableVersion:
|
7 |
| - def __init__(self, version): |
| 7 | + """A wrapper around packaging.version.Version that allows for comparison with strings""" |
| 8 | + |
| 9 | + def __init__(self, version: str) -> None: |
8 | 10 | self.version = Version(version)
|
9 | 11 |
|
10 |
| - def __lt__(self, other: str): |
| 12 | + def __lt__(self, other: object) -> bool: |
11 | 13 | return self._apply_op(other, lambda x, y: x < y)
|
12 | 14 |
|
13 |
| - def __le__(self, other: str): |
| 15 | + def __le__(self, other: object) -> bool: |
14 | 16 | return self._apply_op(other, lambda x, y: x <= y)
|
15 | 17 |
|
16 |
| - def __eq__(self, other: str): |
| 18 | + def __eq__(self, other: object) -> bool: |
17 | 19 | return self._apply_op(other, lambda x, y: x == y)
|
18 | 20 |
|
19 |
| - def __ne__(self, other: str): |
| 21 | + def __ne__(self, other: object) -> bool: |
20 | 22 | return self._apply_op(other, lambda x, y: x != y)
|
21 | 23 |
|
22 |
| - def __gt__(self, other: str): |
| 24 | + def __gt__(self, other: object) -> bool: |
23 | 25 | return self._apply_op(other, lambda x, y: x > y)
|
24 | 26 |
|
25 |
| - def __ge__(self, other: str): |
| 27 | + def __ge__(self, other: object) -> bool: |
26 | 28 | return self._apply_op(other, lambda x, y: x >= y)
|
27 | 29 |
|
28 |
| - def _apply_op(self, other: str, op: Callable[[Version, Version], bool]): |
29 |
| - other = Version(other) |
| 30 | + def _apply_op(self, other: object, op: Callable[[Version, Version], bool]) -> bool: |
| 31 | + other = Version(str(other)) |
30 | 32 | return op(self.version, other)
|
0 commit comments