From ad70a954d0c71d5506143d57c63e58aa09d6a13f Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 25 Nov 2019 11:51:44 +0000 Subject: [PATCH] key.c: Populate `KeyDataStructured' from the keywords. Process the keyword arguments as additional mappings to install in the new object. In particular, `subkeys' is not special any more. --- key.c | 5 ++--- t/t-key.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/key.c b/key.c index 177f01d..d97d632 100644 --- 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; diff --git a/t/t-key.py b/t/t-key.py index bee107b..9e3646f 100644 --- a/t/t-key.py +++ b/t/t-key.py @@ -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) -- 2.11.0