diff options
author | Harmen Stoppels <me@harmenstoppels.nl> | 2024-03-04 08:38:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-04 08:38:54 +0100 |
commit | d1fa23e9c69c15d7e29354a82c7814d6836e0fbd (patch) | |
tree | 3e0fd9698d8b880d9fda46ebb9299ce0c3a01182 /lib | |
parent | f1db8b7871a5f5d1eb29b49787af7248945e872a (diff) | |
download | spack-d1fa23e9c69c15d7e29354a82c7814d6836e0fbd.tar.gz spack-d1fa23e9c69c15d7e29354a82c7814d6836e0fbd.tar.bz2 spack-d1fa23e9c69c15d7e29354a82c7814d6836e0fbd.tar.xz spack-d1fa23e9c69c15d7e29354a82c7814d6836e0fbd.zip |
versions: fix typing problems (#42903)
Fix the type declaration of VersionList.versions.
Fix further problems exposed by that fix.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/version/version_types.py | 14 |
1 files 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 @@ class VersionList: 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.""" |