typed_kwargs: use | for type unions, not ,

Python uses this syntax now, as does typescript and other languages
pull/9599/head
Dylan Baker 3 years ago
parent ecc47d67a9
commit 762c504612
  1. 8
      mesonbuild/interpreterbase/decorators.py
  2. 2
      test cases/failing/116 run_target in test/test.json
  3. 4
      unittests/internaltests.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())))}]"

@ -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]"
}
]
}

@ -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:

Loading…
Cancel
Save