From ecc47d67a945760c3d5e739581fa984bfea6a840 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 19 Nov 2021 10:39:21 -0800 Subject: typed_kwargs: provide better error messages for wrong container types Currently, if you pass a `[]string`, but the argument expects `[]number`, then you get a message like `expected list[str] but got list`. That isn't helpful. With this patch arrays and dictionaries will both print messages with the types provided. --- unittests/internaltests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'unittests') diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 207bd37..86c1890 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 list[str]") def test_typed_kwarg_contained_invalid(self) -> None: @typed_kwargs( @@ -1278,7 +1278,7 @@ class InternalTests(unittest.TestCase): with self.assertRaises(InvalidArguments) as cm: _(None, mock.Mock(), [], {'input': {'key': 1}}) - self.assertEqual(str(cm.exception), "testfunc keyword argument 'input' was of type 'dict' but should have been dict[str]") + self.assertEqual(str(cm.exception), "testfunc keyword argument 'input' was of type dict[int] but should have been dict[str]") def test_typed_kwarg_container_listify(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' but should have been list[str] that has even size") + self.assertEqual(str(cm.exception), "testfunc keyword argument 'input' was of type list[str] but should have been list[str] that has even size") @mock.patch.dict(mesonbuild.mesonlib.project_meson_versions, {}) def test_typed_kwarg_since(self) -> None: -- cgit v1.1