On Sat, Dec 26, 2020 at 11:23:16AM -0000, Anton Abrosimov wrote: > I am trying to release comfortable dataclass unpacking using `**` > operator. Now I have 5 different ways to do it. But not a single good > one. Confused by the implementation of the unpacking operator. > > So when I try to unpack any custom class, I get the error: > > `type object argument after ** must be a mapping, not MyClass` > > Ok, nothing special. I need to use `collections.abc.Mapping` right? > Now I need to implement: `__getitem__`, `__iter__`, `__len__`. Not a problem. > But additionally I get: `keys`, `items`, `values`. > Hey, I don't need them. I don't need the full mapping functionality. I > only need the double asterisk to work.
Why do you want something that isn't a mapping to be usable with mapping unpacking? Does it *really* hurt you to provide mapping methods when you get them for free? Just inherit from Mapping. -- Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/76XZD4JTDNPHDTJBDJWYXUWWQDUUKRDY/ Code of Conduct: http://python.org/psf/codeofconduct/