[Python-ideas] __iter__(), keys(), and the mapping protocol

Jonathan Fine jfine2358 at gmail.com
Thu Sep 13 07:18:07 EDT 2018

Hi Brice

Good comment. I liked it. Not badly off-topic I think, because it
looks to be an interesting work-around for the original problem. You

> But for dataclasses, I'd find it quite useful to have
> {**my_data_class}
> be a shortcut to
> {**dataclasses.asdict(my_data_class)}

How about writing

   fn( ** stst( data_class_obj ) )

where stst() does whatever it is you consider to be the right thing.
My suggestion would be something like

     def stst(obj):

            method = getattr(obj, '__stst')
            if method:
                 return method()
                 return obj

And then it's your responsibility to add an '__stst' attribute to your
data classes.


More information about the Python-ideas mailing list