This makes use of the new convertor and validator arguments, so that we
can check that the languages passed are in fact vaild, and then convert
the native boolean into a MachineChoice internally.
This is meant to allow simple type conversions to happen before the
interpreter function is called. This should simplify some cases like the
"native" keyword arugment that are booleans in the Meson DSL, but an
Enum in the implementation
This attribute is a callable that returns a string if the value is
invalid, otherwise None. This intended for cases like the `install_*`
function's `install_mode` paramater, which is either an int or the
string "preserve", which allows us to do nice things like:
```python
class Kwargs(TypedDict):
install_mode: T.Union[int, T.Literal['preserve']]
@typed_kwargs(
'foo', KwargInfo('install_mode', ...,
validator=lambda x: None if isinstance(x, int) or x == 'preserve' else 'must be the literal "preserve"),
)
def install_data(self, node, args, kwargs: 'Kwargs'):
...
```
In this case mypy *knows* that the string is preserve, as do we, and we
can simply do tests like:
```python
if kwargs['install_mode'] == 'preserve':
...
else:
# this is an int
```
Fix the following Python error:
D:\a\1\s\run_unittests.py:6654: DeprecationWarning: invalid escape sequence \
self.assertEqual(libhello_nolib.get_pkgconfig_variable(escaped_var, {}), hello world)
Use a raw string literal.
Add a method to downgrade an option to disabled if it is not used.
This is useful to avoid unnecessary search for dependencies;
for example
dep = dependency('dep', required: get_option('feature').disable_auto_if(not foo))
can be used instead of the more verbose and complex
if get_option('feature').auto() and not foo then
dep = dependency('', required: false)
else
dep = dependency('dep', required: get_option('feature'))
endif
or to avoid unnecessary dependency searches:
dep1 = dependency('dep1', required: get_option('foo'))
# dep2 is only used together with dep1
dep2 = dependency('dep2', required: get_option('foo').disable_auto_if(not dep1.found()))
```
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Add a method to perform a logical AND on a feature object. The method
also takes care of raising an error if 'enabled' is ANDed with false.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
It's really inconvenient to want a thing that is always a list, but not
be able to provide a default value of a list because of mutation. To
that end the typed_kwargs method now makes a shallow copy of the default
when using a `ContainerTypeInfo` as the type. This mean that using a
default of `[]` is perfectly safe.