From d1fa23e9c69c15d7e29354a82c7814d6836e0fbd Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Mon, 4 Mar 2024 08:38:54 +0100 Subject: [PATCH] versions: fix typing problems (#42903) Fix the type declaration of VersionList.versions. Fix further problems exposed by that fix. --- lib/spack/spack/version/version_types.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/spack/spack/version/version_types.py b/lib/spack/spack/version/version_types.py index bf20224191..e34dc85996 100644 --- a/lib/spack/spack/version/version_types.py +++ b/lib/spack/spack/version/version_types.py @@ -740,7 +740,7 @@ class VersionList: """Sorted, non-redundant list of Version and ClosedOpenRange elements.""" def __init__(self, vlist=None): - self.versions: List[StandardVersion, GitVersion, ClosedOpenRange] = [] + self.versions: List[Union[StandardVersion, GitVersion, ClosedOpenRange]] = [] if vlist is None: pass elif isinstance(vlist, str): @@ -814,16 +814,20 @@ def copy(self): def lowest(self) -> Optional[StandardVersion]: """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]: """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]: """Get the highest numeric version in the list.""" - numeric_versions = list(filter(lambda v: str(v) not in infinity_versions, self.versions)) - return None if not any(numeric_versions) else numeric_versions[-1] + numeric = ( + v + for v in reversed(self.versions) + if isinstance(v, StandardVersion) and not v.isdevelop() + ) + return next(numeric, None) def preferred(self) -> Optional[StandardVersion]: """Get the preferred (latest) version in the list."""