[Python-ideas] add an additional dataclasses.asdict option for non-dataclasses

Chris Angelico rosuav at gmail.com
Sat May 11 20:22:55 EDT 2019


On Sun, May 12, 2019 at 10:14 AM Ricky Teachey <ricky at teachey.org> wrote:
>
> Using iter() for the sole purpose of being able to shoehorn your user class into being dict-cast-able is, IMO, an abuse of iter.
>
> If your class makes logical sense as an iterable of key/value pairs, then for petesake, just use the mapping protocol (implement getitem and keys). iter() is for constructing sequences, not mappings.
>

iter() is for collections of all sorts; a sequence is specifically an
ordered and indexed collection, but you can iterate over many things,
including sets - and mappings. There's nothing wrong with iterable
mappings, and in fact, I would be surprised (and not in a good way) by
any that wasn't.

ChrisA


More information about the Python-ideas mailing list