summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2024-10-01 15:58:24 +0200
committerGitHub <noreply@github.com>2024-10-01 15:58:24 +0200
commit44618e31c8a9d2fc193ac64af1aa859f0942917a (patch)
treec88d9af5f70ae224b9bcbb68e20691a6772dd4bd
parent5bc105c01c0e458924df40d51f7111ba507689f9 (diff)
downloadspack-44618e31c8a9d2fc193ac64af1aa859f0942917a.tar.gz
spack-44618e31c8a9d2fc193ac64af1aa859f0942917a.tar.bz2
spack-44618e31c8a9d2fc193ac64af1aa859f0942917a.tar.xz
spack-44618e31c8a9d2fc193ac64af1aa859f0942917a.zip
stable_partition: use TypeVar (#46686)
-rw-r--r--lib/spack/docs/conf.py2
-rw-r--r--lib/spack/llnl/util/lang.py16
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/spack/docs/conf.py b/lib/spack/docs/conf.py
index c80a661abd..4873e3e104 100644
--- a/lib/spack/docs/conf.py
+++ b/lib/spack/docs/conf.py
@@ -220,6 +220,8 @@ nitpick_ignore = [
("py:class", "spack.filesystem_view.SimpleFilesystemView"),
("py:class", "spack.traverse.EdgeAndDepth"),
("py:class", "archspec.cpu.microarchitecture.Microarchitecture"),
+ # TypeVar that is not handled correctly
+ ("py:class", "llnl.util.lang.T"),
]
# The reST default role (used for this markup: `text`) to use for all documents.
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py
index 736013fe58..5efe27b8b1 100644
--- a/lib/spack/llnl/util/lang.py
+++ b/lib/spack/llnl/util/lang.py
@@ -12,7 +12,7 @@ import re
import sys
import traceback
from datetime import datetime, timedelta
-from typing import Any, Callable, Iterable, List, Tuple
+from typing import Callable, Iterable, List, Tuple, TypeVar
# Ignore emacs backups when listing modules
ignore_modules = r"^\.#|~$"
@@ -879,9 +879,12 @@ def enum(**kwargs):
return type("Enum", (object,), kwargs)
+T = TypeVar("T")
+
+
def stable_partition(
- input_iterable: Iterable, predicate_fn: Callable[[Any], bool]
-) -> Tuple[List[Any], List[Any]]:
+ input_iterable: Iterable[T], predicate_fn: Callable[[T], bool]
+) -> Tuple[List[T], List[T]]:
"""Partition the input iterable according to a custom predicate.
Args:
@@ -893,12 +896,13 @@ def stable_partition(
Tuple of the list of elements evaluating to True, and
list of elements evaluating to False.
"""
- true_items, false_items = [], []
+ true_items: List[T] = []
+ false_items: List[T] = []
for item in input_iterable:
if predicate_fn(item):
true_items.append(item)
- continue
- false_items.append(item)
+ else:
+ false_items.append(item)
return true_items, false_items