8000 fix(core): Typing in version by Tranquility2 · Pull Request #701 · testcontainers/testcontainers-python · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions core/testcontainers/core/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@


class ComparableVersion:
def __init__(self, version):
"""A wrapper around packaging.version.Version that allows for comparison with strings"""

def __init__(self, version: str) -> None:
self.version = Version(version)

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

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

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

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

def __gt__(self, other: str):
def __gt__(self, other: object) -> bool:
return self._apply_op(other, lambda x, y: x > y)

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

def _apply_op(self, other: str, op: Callable[[Version, Version], bool]):
other = Version(other)
def _apply_op(self, other: object, op: Callable[[Version, Version], bool]) -> bool:
other = Version(str(other))
return op(self.version, other)
0