2020-12-28 Christopher Barker <pythonchb@gmail.com> dixit:
I don't know about the OP, but all I wanted was a clear definition of the part of the API needed to support **, and apparently it's a keys() method that returns an iterator of the keys, and a __getitem__ [...]
To be more precise: an *iterable* of the keys -- not necessarily an *iterator*; it can be, for example, a list or string: >>> def fun(**kwargs):print(kwargs) ... >>> class C: ... def keys(self): return list('abc') ... def __getitem__(self, key): return 42 ... >>> c = C() >>> fun(**c) {'a': 42, 'c': 42, 'b': 42} And, even, the `keys()` method does not need to be defined on the class level -- it can be a callable attribute of an *instance*: >>> class D: ... def __getitem__(self, key): return 42 ... >>> d = D() >>> d.keys = lambda: 'abc' >>> fun(**d) {'a': 42, 'c': 42, 'b': 42} Cheers, *j