aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-06-14 19:25:33 -0400
committerEli Schwartz <eschwartz@archlinux.org>2022-06-17 14:33:01 -0400
commitc1aeb2f7e4ef81a046ca28d5dad89bb8fdeefafd (patch)
tree4aa074a1dd499b1b9280645898771aebf9b755c7
parentb49b9f52b29896cce58a1e3dbeb1b6cf54420d45 (diff)
downloadmeson-c1aeb2f7e4ef81a046ca28d5dad89bb8fdeefafd.zip
meson-c1aeb2f7e4ef81a046ca28d5dad89bb8fdeefafd.tar.gz
meson-c1aeb2f7e4ef81a046ca28d5dad89bb8fdeefafd.tar.bz2
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.
-rw-r--r--mesonbuild/interpreterbase/decorators.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/mesonbuild/interpreterbase/decorators.py b/mesonbuild/interpreterbase/decorators.py
index a98e999..5dd8b89 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)