versions: fix typing problems (#42903)

Fix the type declaration of VersionList.versions.

Fix further problems exposed by that fix.
This commit is contained in:
Harmen Stoppels 2024-03-04 08:38:54 +01:00 committed by GitHub
parent f1db8b7871
commit d1fa23e9c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -740,7 +740,7 @@ class VersionList:
"""Sorted, non-redundant list of Version and ClosedOpenRange elements.""" """Sorted, non-redundant list of Version and ClosedOpenRange elements."""
def __init__(self, vlist=None): def __init__(self, vlist=None):
self.versions: List[StandardVersion, GitVersion, ClosedOpenRange] = [] self.versions: List[Union[StandardVersion, GitVersion, ClosedOpenRange]] = []
if vlist is None: if vlist is None:
pass pass
elif isinstance(vlist, str): elif isinstance(vlist, str):
@ -814,16 +814,20 @@ def copy(self):
def lowest(self) -> Optional[StandardVersion]: def lowest(self) -> Optional[StandardVersion]:
"""Get the lowest version in the list.""" """Get the lowest version in the list."""
return None if not self else self[0] return next((v for v in self.versions if isinstance(v, StandardVersion)), None)
def highest(self) -> Optional[StandardVersion]: def highest(self) -> Optional[StandardVersion]:
"""Get the highest version in the list.""" """Get the highest version in the list."""
return None if not self else self[-1] return next((v for v in reversed(self.versions) if isinstance(v, StandardVersion)), None)
def highest_numeric(self) -> Optional[StandardVersion]: def highest_numeric(self) -> Optional[StandardVersion]:
"""Get the highest numeric version in the list.""" """Get the highest numeric version in the list."""
numeric_versions = list(filter(lambda v: str(v) not in infinity_versions, self.versions)) numeric = (
return None if not any(numeric_versions) else numeric_versions[-1] v
for v in reversed(self.versions)
if isinstance(v, StandardVersion) and not v.isdevelop()
)
return next(numeric, None)
def preferred(self) -> Optional[StandardVersion]: def preferred(self) -> Optional[StandardVersion]:
"""Get the preferred (latest) version in the list.""" """Get the preferred (latest) version in the list."""