aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter/interpreter.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-06-02 15:45:15 -0700
committerDaniel Mensinger <daniel@mensinger-ka.de>2021-06-08 11:00:55 +0200
commitfb385728df5d14c929420c6fd0fb2958f274761d (patch)
tree349e686a476fec3406520b69a335f4db327bad83 /mesonbuild/interpreter/interpreter.py
parent5d81392c67231fa68a67bdacf2a2764ef3e76da5 (diff)
downloadmeson-fb385728df5d14c929420c6fd0fb2958f274761d.zip
meson-fb385728df5d14c929420c6fd0fb2958f274761d.tar.gz
meson-fb385728df5d14c929420c6fd0fb2958f274761d.tar.bz2
interpreterbase: Add validator keyword argument to typed_kwargs
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 ```
Diffstat (limited to 'mesonbuild/interpreter/interpreter.py')
0 files changed, 0 insertions, 0 deletions