diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-08-27 11:03:42 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2021-08-27 14:54:30 -0700 |
commit | ce392acad4ee0c2eb8c15742d8194f82f88eb131 (patch) | |
tree | 1376cba0bb38fd4d355bb2110344aa555c629d5a | |
parent | 11fbaf29d8444ca35269a938e46327dfbe7820bd (diff) | |
download | meson-ce392acad4ee0c2eb8c15742d8194f82f88eb131.zip meson-ce392acad4ee0c2eb8c15742d8194f82f88eb131.tar.gz meson-ce392acad4ee0c2eb8c15742d8194f82f88eb131.tar.bz2 |
interpreterbase: ensure that the default vaule to KwargInfo is a valid type
Because currently you can write something like:
```python
KwargInfo('capture', bool)
```
Which proclaims "this must be bool", but the default is then not valid.
-rw-r--r-- | mesonbuild/interpreterbase/decorators.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/mesonbuild/interpreterbase/decorators.py b/mesonbuild/interpreterbase/decorators.py index 2f59dd7..6aa4fca 100644 --- a/mesonbuild/interpreterbase/decorators.py +++ b/mesonbuild/interpreterbase/decorators.py @@ -467,8 +467,12 @@ def typed_kwargs(name: str, *types: KwargInfo) -> T.Callable[..., T.Any]: # conversion if necessary). This allows mutable types to # be used safely as default values if isinstance(info.types, ContainerTypeInfo): + assert isinstance(info.default, info.types.container), f'In function {name} default value of {info.name} is not a valid type, got {type(info.default)}, expected {info.types.container}[{info.types.contains}]' + for item in info.default: + assert isinstance(item, info.types.contains), f'In function {name} default value of {info.name}, container has invalid value of {item}, which is of type {type(item)}, but should be {info.types.contains}' kwargs[info.name] = info.types.container(info.default) else: + assert isinstance(info.default, info.types), f'In funcion {name} default value of {info.name} is not a valid type, got {type(info.default)} expected {info.types}' kwargs[info.name] = info.default if info.not_set_warning: mlog.warning(info.not_set_warning) |