key.c: Populate `KeyDataStructured' from the keywords.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 25 Nov 2019 11:51:44 +0000 (11:51 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 11 Apr 2020 11:49:31 +0000 (12:49 +0100)
Process the keyword arguments as additional mappings to install in the
new object.  In particular, `subkeys' is not special any more.

key.c
t/t-key.py

diff --git a/key.c b/key.c
index 177f01d..d97d632 100644 (file)
--- a/key.c
+++ b/key.c
@@ -1046,12 +1046,11 @@ static PyObject *keydatastruct_pynew(PyTypeObject *ty,
   PyObject *sub = 0;
   keydata_pyobj *me = 0;
   key_data *kd = 0;
-  static const char *const kwlist[] = { "subkeys", 0 };
 
-  if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O:new", KWLIST, &sub))
-    goto end;
+  if (!PyArg_ParseTuple(arg, "|O:new", &sub)) goto end;
   kd = key_newstruct();
   if (sub && populate_struct(kd, sub)) goto end;
+  if (kw && populate_struct(kd, kw)) goto end;
   me = (keydata_pyobj *)ty->tp_alloc(ty, 0);
   me->gmops = &keydatastruct_gmops;
   me->kd = kd; kd = 0;
index bee107b..9e3646f 100644 (file)
@@ -288,9 +288,9 @@ class TestKeyData (U.TestCase):
   def test_struct(me):
     rng = T.detrand("kd-struct")
     kd = C.KeyDataStructured({ "a": C.KeyDataString("a"),
-                               "b": C.KeyDataString("b"),
-                               "c": C.KeyDataString("c"),
-                               "d": C.KeyDataString("d") })
+                               "b": C.KeyDataString("b") },
+                             c = C.KeyDataString("c"),
+                             d = C.KeyDataString("d"))
     for i in ["a", "b", "c", "d"]: me.assertEqual(kd[i].str, i)
     me.assertEqual(len(kd), 4)
     me.check_encode(kd)