dict
can be called using iteration of pairs, so if you create your own __iter__
to return the iteration of tuples, your example works as you would like:
class Foo:
def __iter__(self):
yield from {
'this': 'is',
'a': 'dict'
}.items()
dict(Foo())
{'a': 'dict', 'this': 'is'}
, python, , , , abc.Mapping
.
, __getitem__
, __iter__
__len__
abc.Mapping
, __getitem__
, __iter__
, __len__
__contains__
, keys
, items
, values
, get
, __eq__
__ne__
.