From f5a133608a72a96b2023024043dc00480192bcc7 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 25 Nov 2019 11:54:12 +0000 Subject: [PATCH] key.c: Complain about duplicate subkeys passed to `KeyDataStructured'. This wasn't previously possible (without complicated subterfuge), but now a keyword argument can duplicate a mapping set in the positional argument. --- key.c | 1 + t/t-key.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/key.c b/key.c index d97d632..017c973 100644 --- a/key.c +++ b/key.c @@ -1029,6 +1029,7 @@ static int populate_struct(key_data *kd, PyObject *map) goto end; if (!KEYDATA_PYCHECK(val)) TYERR("subkey objects must be instances of KeyData"); + if (key_structfind(kd, p)) VALERR("duplicate tag"); key_structset(kd, p, KEYDATA_KD(val)); Py_DECREF(name); name = 0; Py_DECREF(val); val = 0; diff --git a/t/t-key.py b/t/t-key.py index 9e3646f..000dc11 100644 --- a/t/t-key.py +++ b/t/t-key.py @@ -295,6 +295,9 @@ class TestKeyData (U.TestCase): me.assertEqual(len(kd), 4) me.check_encode(kd) me.assertRaises(TypeError, C.KeyDataStructured, { "a": "a" }) + me.assertRaises(ValueError, C.KeyDataStructured, + { "a": C.KeyDataString("a") }, + a = C.KeyDataString("b")) ###-------------------------------------------------------------------------- ### Mappings. -- 2.11.0