FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(core): Typing in version by Tranquility2 · Pull Request #701 · testcontainers/testcontainers-python · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
20 changes: 11 additions & 9 deletions core/testcontainers/core/version.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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)

Back | FazBrowse Home | New Git URL