[Python-Dev] Python 3.6 dict becomes compact and gets a private version; and keywords become ordered (original) (raw)

Gregory P. Smith greg at krypto.org
Mon Sep 12 18:28:18 EDT 2016


On Mon, Sep 12, 2016 at 9:51 AM Chris Angelico <rosuav at gmail.com> wrote:

On Tue, Sep 13, 2016 at 2:27 AM, Gregory P. Smith <greg at krypto.org> wrote: > Disorder for this purpose need not be a random shuffle (overkill). It just > needs to be regularly inconsistent. A simple thing to do on top of 3.6's new > dict implementation would be to pick a random starting point within the > order array rather than offset 0 to start iteration from. That small change > would be sufficient to guarantee that code depending on order must ask for > order. It could even allow us to get people ready for iteration within the > same process to become unstable.

Don't forget that .items(), .keys(), and .values() are all synchronized, so you'd probably have to pick an offset at dict creation and run with it forever after.

Indeed. We could "cheat" and match existing 2.7 and 3.5 behavior by using the hash randomization seed to determine a "consistent within the life of a process" dict iteration order randomization without storing anything per dict. That has the added bonus/drawback (POV) of allowing people to fix a specific behavior via the existing environment variable as they already expect.

But given my previous message deciding trying to implement disordered iteration by default in some cases is infeasible, it's moot. :)

-gps -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160912/3201da2f/attachment.html>



More information about the Python-Dev mailing list