aboutsummaryrefslogtreecommitdiff
path: root/run_unittests.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2021-06-01 15:48:23 -0700
committerDylan Baker <dylan@pnwbakers.com>2021-06-04 20:10:05 -0700
commitb107171307505e1493f76b53ace7db1ac070e819 (patch)
treedf6053ee1233a2439e21b4759dbbdf59d476921d /run_unittests.py
parent8890a624997a9cf56ead08bda03e9b46803986ad (diff)
downloadmeson-b107171307505e1493f76b53ace7db1ac070e819.zip
meson-b107171307505e1493f76b53ace7db1ac070e819.tar.gz
meson-b107171307505e1493f76b53ace7db1ac070e819.tar.bz2
interpreterbase: Allow safely using mutable default values with typed_kwargs
It's really inconvenient to want a thing that is always a list, but not be able to provide a default value of a list because of mutation. To that end the typed_kwargs method now makes a shallow copy of the default when using a `ContainerTypeInfo` as the type. This mean that using a default of `[]` is perfectly safe.
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-xrun_unittests.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/run_unittests.py b/run_unittests.py
index e278675..a0beb48 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -1574,6 +1574,17 @@ class InternalTests(unittest.TestCase):
_(None, mock.Mock(), [], {'input': 'str'})
+ def test_typed_kwarg_container_default_copy(self) -> None:
+ default: T.List[str] = []
+ @typed_kwargs(
+ 'testfunc',
+ KwargInfo('input', ContainerTypeInfo(list, str), listify=True, default=default),
+ )
+ def _(obj, node, args: T.Tuple, kwargs: T.Dict[str, T.List[str]]) -> None:
+ self.assertIsNot(kwargs['input'], default)
+
+ _(None, mock.Mock(), [], {})
+
def test_typed_kwarg_container_pairs(self) -> None:
@typed_kwargs(
'testfunc',