interpreterbase/decorators: fix typed_kwargs return type

Because of the convertor function we have no guarantee that what we're
getting is in fact a `Dict[str, TYPE_var]`, it might well be anything in
the values, so we need to do some casting and set the return type to
object. This works out fine in practice as our declared `TypeDict`
inputs in the actual function signatures will be used instead.
pull/9066/head
Dylan Baker 4 years ago committed by Xavier Claessens
parent f4a1da0145
commit 386b312fa9
  1. 6
      mesonbuild/interpreterbase/decorators.py

@ -323,7 +323,7 @@ class KwargInfo(T.Generic[_T]):
deprecated: T.Optional[str] = None,
deprecated_values: T.Optional[T.Dict[str, str]] = None,
validator: T.Optional[T.Callable[[_T], T.Optional[str]]] = None,
convertor: T.Optional[T.Callable[[_T], TYPE_var]] = None,
convertor: T.Optional[T.Callable[[_T], object]] = None,
not_set_warning: T.Optional[str] = None):
self.name = name
self.types = types
@ -394,7 +394,9 @@ 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:
kwargs, subproject = get_callee_args(wrapped_args, want_subproject=True)[3:5]
_kwargs, subproject = get_callee_args(wrapped_args, want_subproject=True)[3:5]
# Cast here, as the convertor function may place something other than a TYPE_var in the kwargs
kwargs = T.cast(T.Dict[str, object], _kwargs)
all_names = {t.name for t in types}
unknowns = set(kwargs).difference(all_names)

Loading…
Cancel
Save