diff options
| author | Eli Schwartz <eschwartz@archlinux.org> | 2022-06-14 19:25:33 -0400 |
|---|---|---|
| committer | Eli Schwartz <eschwartz@archlinux.org> | 2022-06-17 14:33:01 -0400 |
| commit | c1aeb2f7e4ef81a046ca28d5dad89bb8fdeefafd (patch) | |
| tree | 4aa074a1dd499b1b9280645898771aebf9b755c7 /mesonbuild/interpreterbase/decorators.py | |
| parent | b49b9f52b29896cce58a1e3dbeb1b6cf54420d45 (diff) | |
| download | meson-c1aeb2f7e4ef81a046ca28d5dad89bb8fdeefafd.tar.gz | |
typed_kwargs: support dict/list as "new since" types
Given a kwarg value that is itself a dict/list, we would only check if
the since_values was present within that container. If the since_values
is itself the dict or list type, then we aren't looking for recursive
structures, we just want to know when the function began to accept that
type.
This is relevant in cases where a function accepted a dict, and at one
point began accepting a list (of strings in the form 'key=value'), or
vice versa.
Diffstat (limited to 'mesonbuild/interpreterbase/decorators.py')
| -rw-r--r-- | mesonbuild/interpreterbase/decorators.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/mesonbuild/interpreterbase/decorators.py b/mesonbuild/interpreterbase/decorators.py index a98e9990d..5dd8b8982 100644 --- a/mesonbuild/interpreterbase/decorators.py +++ b/mesonbuild/interpreterbase/decorators.py @@ -505,18 +505,24 @@ def typed_kwargs(name: str, *types: KwargInfo) -> T.Callable[..., T.Any]: @wraps(f) def wrapper(*wrapped_args: T.Any, **wrapped_kwargs: T.Any) -> T.Any: - def emit_feature_change(values: T.Dict[str, T.Union[str, T.Tuple[str, str]]], feature: T.Union[T.Type['FeatureDeprecated'], T.Type['FeatureNew']]) -> None: + def emit_feature_change(values: T.Dict[_T, T.Union[str, T.Tuple[str, str]]], feature: T.Union[T.Type['FeatureDeprecated'], T.Type['FeatureNew']]) -> None: for n, version in values.items(): - if isinstance(value, (dict, list)): + warn = False + if isinstance(version, tuple): + version, msg = version + else: + msg = None + + if n in {dict, list}: + assert isinstance(n, type), 'for mypy' + if isinstance(value, n): + feature.single_use(f'"{name}" keyword argument "{info.name}" of type {n.__name__}', version, subproject, msg, location=node) + elif isinstance(value, (dict, list)): warn = n in value else: warn = n == value if warn: - if isinstance(version, tuple): - version, msg = version - else: - msg = None feature.single_use(f'"{name}" keyword argument "{info.name}" value "{n}"', version, subproject, msg, location=node) node, _, _kwargs, subproject = get_callee_args(wrapped_args) |
