3 ms·
Sure, but why did you enable the -R flag? We are talking about the default way of doing things in the most commonly by far used implementation. I'm not saying
by lqdc13 11y ago
Sure, but why did you enable the -R flag?
We are talking about the default way of doing things in the most commonly by far used implementation.
I'm not saying someone should have relied on the specific ordering or that the code that does rely on it is a great way of doing things.
CPython2 did make that promise -
CPython implementation detail: Keys and values are listed in an arbitrary order which is non-random, varies across Python implementations, and depends on the dictionary’s history of insertions and deletions.
In other words, the order should be the same no matter how many times you restart the application.
It is a subtle source of bugs since it always worked in each specific version of CPython2 without the -R flag.
- dalke 11y ago"why did you enable the -R flag?" Because either the documentation means to include -R in the description, in which case your interpretation of the documentation is incorrect, or the documentation is incomplete because it doesn't describe a valid CPython 2.x run-time. Either way, it indicates that the difference isn't, strictly speaking, a Python2/3 issue. "an arbitrary order" Where does it say that the arbitrary order must be consistent across multiple invocations? Quoting from https://docs.python.org/2/using/cmdline.html#cmdoption-R https://docs.python.org/2/using/cmdline.html#cmdoption-R : > Changing hash values affects the order in which keys are retrieved from a dict. Although Python has never made guarantees about this ordering (and it typically varies between 32-bit and 64-bit builds), enough real-world code implicitly relies on this non-guaranteed behavior that the randomization is disabled by default. I totally understand your point. I remember the debates about how this would break code. But it's there to mitigate algorithmic complexity attacks against an every increasing attack surface. This was the best solution they come up with, along with a migration path to the new default.