Skip to content

Commit 3d5e22d

Browse files
committed
fix(core): Typing in version
1 parent 2061912 commit 3d5e22d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

core/testcontainers/core/version.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@
44

55

66
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:
810
self.version = Version(version)
911

10-
def __lt__(self, other: str):
12+
def __lt__(self, other: object) -> bool:
1113
return self._apply_op(other, lambda x, y: x < y)
1214

13-
def __le__(self, other: str):
15+
def __le__(self, other: object) -> bool:
1416
return self._apply_op(other, lambda x, y: x <= y)
1517

16-
def __eq__(self, other: str):
18+
def __eq__(self, other: object) -> bool:
1719
return self._apply_op(other, lambda x, y: x == y)
1820

19-
def __ne__(self, other: str):
21+
def __ne__(self, other: object) -> bool:
2022
return self._apply_op(other, lambda x, y: x != y)
2123

22-
def __gt__(self, other: str):
24+
def __gt__(self, other: object) -> bool:
2325
return self._apply_op(other, lambda x, y: x > y)
2426

25-
def __ge__(self, other: str):
27+
def __ge__(self, other: object) -> bool:
2628
return self._apply_op(other, lambda x, y: x >= y)
2729

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))
3032
return op(self.version, other)

0 commit comments

Comments
 (0)