From 762c504612a15109451c647752227be352e15e62 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 19 Nov 2021 10:42:38 -0800 Subject: [PATCH] typed_kwargs: use | for type unions, not , Python uses this syntax now, as does typescript and other languages --- mesonbuild/interpreterbase/decorators.py | 8 ++++---- test cases/failing/116 run_target in test/test.json | 2 +- unittests/internaltests.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mesonbuild/interpreterbase/decorators.py b/mesonbuild/interpreterbase/decorators.py index 817cb85bc..8832d294d 100644 --- a/mesonbuild/interpreterbase/decorators.py +++ b/mesonbuild/interpreterbase/decorators.py @@ -326,9 +326,9 @@ class ContainerTypeInfo: :return: string to be printed """ - container = 'dict' if self.container is dict else 'list' + container = 'dict' if self.container is dict else 'array' if isinstance(self.contains, tuple): - contains = ','.join([t.__name__ for t in self.contains]) + contains = ' | '.join([t.__name__ for t in self.contains]) else: contains = self.contains.__name__ s = f'{container}[{contains}]' @@ -471,8 +471,8 @@ def typed_kwargs(name: str, *types: KwargInfo) -> T.Callable[..., T.Any]: """describe a raw type (ie, one that is not a ContainerTypeInfo).""" if isinstance(t, list): if t: - return f"list[{' | '.join(sorted(mesonlib.OrderedSet(type(v).__name__ for v in t)))}]" - return 'list[]' + return f"array[{' | '.join(sorted(mesonlib.OrderedSet(type(v).__name__ for v in t)))}]" + return 'array[]' elif isinstance(t, dict): if t: return f"dict[{' | '.join(sorted(mesonlib.OrderedSet(type(v).__name__ for v in t.values())))}]" diff --git a/test cases/failing/116 run_target in test/test.json b/test cases/failing/116 run_target in test/test.json index 7826ceb38..e08aa03b2 100644 --- a/test cases/failing/116 run_target in test/test.json +++ b/test cases/failing/116 run_target in test/test.json @@ -1,7 +1,7 @@ { "stdout": [ { - "line": "test cases/failing/116 run_target in test/meson.build:4:0: ERROR: test keyword argument 'args' was of type list[RunTarget] but should have been list[str,File,BuildTarget,CustomTarget]" + "line": "test cases/failing/116 run_target in test/meson.build:4:0: ERROR: test keyword argument 'args' was of type array[RunTarget] but should have been array[str | File | BuildTarget | CustomTarget]" } ] } diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 86c189045..93affb766 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -1266,7 +1266,7 @@ class InternalTests(unittest.TestCase): with self.assertRaises(InvalidArguments) as cm: _(None, mock.Mock(), [], {'input': {}}) - self.assertEqual(str(cm.exception), "testfunc keyword argument 'input' was of type dict[] but should have been list[str]") + self.assertEqual(str(cm.exception), "testfunc keyword argument 'input' was of type dict[] but should have been array[str]") def test_typed_kwarg_contained_invalid(self) -> None: @typed_kwargs( @@ -1313,7 +1313,7 @@ class InternalTests(unittest.TestCase): with self.assertRaises(MesonException) as cm: _(None, mock.Mock(), [], {'input': ['a']}) - self.assertEqual(str(cm.exception), "testfunc keyword argument 'input' was of type list[str] but should have been list[str] that has even size") + self.assertEqual(str(cm.exception), "testfunc keyword argument 'input' was of type array[str] but should have been array[str] that has even size") @mock.patch.dict(mesonbuild.mesonlib.project_meson_versions, {}) def test_typed_kwarg_since(self) -> None: