summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2024-11-29 23:17:28 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2024-12-04 22:49:18 -0800
commitf54526957aff1485f975302375c4feec917c2762 (patch)
treefb637315328d987c81ce0ba9b2ed3a5c510f8918 /lib
parent175a4bf101adf7eb6071e13159881510928a5344 (diff)
downloadspack-f54526957aff1485f975302375c4feec917c2762.tar.gz
spack-f54526957aff1485f975302375c4feec917c2762.tar.bz2
spack-f54526957aff1485f975302375c4feec917c2762.tar.xz
spack-f54526957aff1485f975302375c4feec917c2762.zip
directives: add type annotations to `DirectiveMeta` class
Some of the class-level annotations were wrong, and some were missing. Annotate all the functions here and fix the class properties to match what's actually happening. Signed-off-by: Todd Gamblin <tgamblin@llnl.gov>
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/directives_meta.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/spack/spack/directives_meta.py b/lib/spack/spack/directives_meta.py
index 70ba0298a8..0ba1acb7bb 100644
--- a/lib/spack/spack/directives_meta.py
+++ b/lib/spack/spack/directives_meta.py
@@ -5,7 +5,7 @@
import collections.abc
import functools
-from typing import List, Set
+from typing import Any, Callable, Dict, List, Optional, Sequence, Set, Type, Union
import llnl.util.lang
@@ -25,11 +25,13 @@ class DirectiveMeta(type):
# Set of all known directives
_directive_dict_names: Set[str] = set()
- _directives_to_be_executed: List[str] = []
- _when_constraints_from_context: List[str] = []
+ _directives_to_be_executed: List[Callable] = []
+ _when_constraints_from_context: List[spack.spec.Spec] = []
_default_args: List[dict] = []
- def __new__(cls, name, bases, attr_dict):
+ def __new__(
+ cls: Type["DirectiveMeta"], name: str, bases: tuple, attr_dict: dict
+ ) -> "DirectiveMeta":
# Initialize the attribute containing the list of directives
# to be executed. Here we go reversed because we want to execute
# commands:
@@ -60,7 +62,7 @@ class DirectiveMeta(type):
return super(DirectiveMeta, cls).__new__(cls, name, bases, attr_dict)
- def __init__(cls, name, bases, attr_dict):
+ def __init__(cls: "DirectiveMeta", name: str, bases: tuple, attr_dict: dict):
# The instance is being initialized: if it is a package we must ensure
# that the directives are called to set it up.
@@ -81,27 +83,27 @@ class DirectiveMeta(type):
super(DirectiveMeta, cls).__init__(name, bases, attr_dict)
@staticmethod
- def push_to_context(when_spec):
+ def push_to_context(when_spec: spack.spec.Spec) -> None:
"""Add a spec to the context constraints."""
DirectiveMeta._when_constraints_from_context.append(when_spec)
@staticmethod
- def pop_from_context():
+ def pop_from_context() -> spack.spec.Spec:
"""Pop the last constraint from the context"""
return DirectiveMeta._when_constraints_from_context.pop()
@staticmethod
- def push_default_args(default_args):
+ def push_default_args(default_args: Dict[str, Any]) -> None:
"""Push default arguments"""
DirectiveMeta._default_args.append(default_args)
@staticmethod
- def pop_default_args():
+ def pop_default_args() -> dict:
"""Pop default arguments"""
return DirectiveMeta._default_args.pop()
@staticmethod
- def directive(dicts=None):
+ def directive(dicts: Optional[Union[Sequence[str], str]] = None) -> Callable:
"""Decorator for Spack directives.
Spack directives allow you to modify a package while it is being
@@ -156,7 +158,7 @@ class DirectiveMeta(type):
DirectiveMeta._directive_dict_names |= set(dicts)
# This decorator just returns the directive functions
- def _decorator(decorated_function):
+ def _decorator(decorated_function: Callable) -> Callable:
directive_names.append(decorated_function.__name__)
@functools.wraps(decorated_function)