From 82136da933f0859edd6cf168a129ede706e9e055 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 1 Dec 2021 15:45:48 -0800 Subject: interpreterbase/decorators: Fix types of deprecated_values and since_values Which shouldn't be Dict[str, str], they should be Dict[_T, str], as nay value that can be passed to types is valid here. --- mesonbuild/interpreterbase/decorators.py | 5 +++-- unittests/internaltests.py | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mesonbuild/interpreterbase/decorators.py b/mesonbuild/interpreterbase/decorators.py index 8c849e986..9434ab709 100644 --- a/mesonbuild/interpreterbase/decorators.py +++ b/mesonbuild/interpreterbase/decorators.py @@ -372,7 +372,8 @@ class KwargInfo(T.Generic[_T]): string, but the implementation using an Enum. This should not do validation, just conversion. :param deprecated_values: a dictionary mapping a value to the version of - meson it was deprecated in. + meson it was deprecated in. The Value may be any valid value for this + argument. :param since_values: a dictionary mapping a value to the version of meson it was added in. :param not_set_warning: A warning message that is logged if the kwarg is not @@ -385,7 +386,7 @@ class KwargInfo(T.Generic[_T]): since: T.Optional[str] = None, since_values: T.Optional[T.Dict[str, str]] = None, deprecated: T.Optional[str] = None, - deprecated_values: T.Optional[T.Dict[str, str]] = None, + deprecated_values: T.Optional[T.Dict[_T, str]] = None, validator: T.Optional[T.Callable[[T.Any], T.Optional[str]]] = None, convertor: T.Optional[T.Callable[[_T], object]] = None, not_set_warning: T.Optional[str] = None): diff --git a/unittests/internaltests.py b/unittests/internaltests.py index c4fd0a695..4135655ee 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -1378,6 +1378,7 @@ class InternalTests(unittest.TestCase): 'testfunc', KwargInfo('input', ContainerTypeInfo(list, str), listify=True, default=[], deprecated_values={'foo': '0.9'}, since_values={'bar': '1.1'}), KwargInfo('output', ContainerTypeInfo(dict, str), default={}, deprecated_values={'foo': '0.9'}, since_values={'bar': '1.1'}), + KwargInfo('install_dir', (bool, str, NoneType), deprecated_values={False: '0.9'}), KwargInfo( 'mode', (str, type(None)), @@ -1402,6 +1403,10 @@ class InternalTests(unittest.TestCase): _(None, mock.Mock(subproject=''), [], {'output': {'foo': 'a'}}) self.assertRegex(out.getvalue(), r"""WARNING:.Project targeting '1.0'.*deprecated since '0.9': "testfunc" keyword argument "output" value "foo".*""") + with mock.patch('sys.stdout', io.StringIO()) as out: + _(None, mock.Mock(subproject=''), [], {'install_dir': False}) + self.assertRegex(out.getvalue(), r"""WARNING:.Project targeting '1.0'.*deprecated since '0.9': "testfunc" keyword argument "install_dir" value "False".*""") + with mock.patch('sys.stdout', io.StringIO()) as out: _(None, mock.Mock(subproject=''), [], {'output': {'bar': 'b'}}) self.assertRegex(out.getvalue(), r"""WARNING:.Project targeting '1.0'.*introduced in '1.1': "testfunc" keyword argument "output" value "bar".*""") -- cgit v1.2.3