[Python-Dev] How to update namedtuple asdict() to use dict instead of OrderedDict

Barry Warsaw barry at python.org
Wed Jan 30 20:07:19 EST 2019


On Jan 30, 2019, at 14:32, Raymond Hettinger <raymond.hettinger at gmail.com> wrote:
> 
> Now that regular dicts are ordered and compact, it makes more sense for the _asdict() method to create a regular dict (as it did in its early days) rather than an OrderedDict.  The regular dict is much smaller, much faster, and has a much cleaner looking repr.  It would also help namedtuple() stay in sync with dataclasses which already take advantage of the ordering feature of regular dicts.

Thanks for the excellent write up, Raymond.

> Option 1) Add a deprecation notice to 3.8 […]

In general, I don’t favor deprecation notices for things that are not actionable by the end user or the consumer of the API in question.  It ends up being just noise, and that’s one of the big reasons why they are silenced by default (i.e. the end user of a Python application can’t do anything about the deprecation, so why scare them?).

Maybe we need something like a MinorBehavioralChangeWarning which would be surfaced similar to PendingDeprecationWarning, but which says “Hey, we changed this in the current version of Python.  Be aware of that change, but you probably don’t need to do anything about it”.  At least such warnings could be reviewed, documented, and audited.

I suppose in this case, there is something the consumer of the API can do (as you point out, they can wrap their code), but in all likelihood there’s really nothing they *need* to do.  I think it will be rare that a Python 3.8 user will get bitten by this.  Therefore...

> Option 4) Just make the change directly in 3.8,

JFDI!

-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://mail.python.org/pipermail/python-dev/attachments/20190130/71b0fd04/attachment.sig>


More information about the Python-Dev mailing list