Skip to content

Commit 9dc2a02

Browse files
authored
fix(core): Typing in version (#701)
Supports: #305 Related : #691 #692 #700 ``` poetry run mypy --config-file pyproject.toml core/testcontainers/core/version.py Success: no issues found in 1 source file ``` Old ``` Error Summary ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓ ┃ File Path ┃ Errors ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩ │ core/testcontainers/core/version.py │ 12 │ │ core/testcontainers/core/docker_client.py │ 14 │ │ core/testcontainers/core/image.py │ 17 │ │ core/testcontainers/core/waiting_utils.py │ 8 │ │ core/testcontainers/core/container.py │ 20 │ │ core/tests/test_new_docker_api.py │ 4 │ │ core/tests/test_docker_in_docker.py │ 2 │ │ core/testcontainers/compose/compose.py │ 22 │ │ core/testcontainers/compose/__init__.py │ 2 │ │ core/tests/test_version.py │ 2 │ │ core/tests/test_ryuk.py │ 2 │ │ core/tests/test_registry.py │ 1 │ │ core/tests/test_image.py │ 3 │ │ core/tests/test_compose.py │ 7 │ └───────────────────────────────────────────┴────────┘ Found 116 errors in 14 files. ``` New ``` Error Summary ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓ ┃ File Path ┃ Errors ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩ │ core/testcontainers/core/docker_client.py │ 14 │ │ core/testcontainers/core/image.py │ 17 │ │ core/testcontainers/core/waiting_utils.py │ 8 │ │ core/testcontainers/core/container.py │ 20 │ │ core/tests/test_new_docker_api.py │ 4 │ │ core/tests/test_docker_in_docker.py │ 2 │ │ core/testcontainers/compose/compose.py │ 22 │ │ core/testcontainers/compose/__init__.py │ 2 │ │ core/tests/test_ryuk.py │ 2 │ │ core/tests/test_registry.py │ 1 │ │ core/tests/test_image.py │ 3 │ │ core/tests/test_compose.py │ 7 │ └───────────────────────────────────────────┴────────┘ Found 102 errors in 12 files. ```
1 parent 2061912 commit 9dc2a02

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)