frozendict

Nathan Rice nathan.alexander.rice at gmail.com
Thu Feb 9 21:30:46 EST 2012


On Thu, Feb 9, 2012 at 8:24 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Thu, 09 Feb 2012 09:35:52 -0700, Ian Kelly wrote:
>
>> On Thu, Feb 9, 2012 at 8:19 AM, Nathan Rice
>> <nathan.alexander.rice at gmail.com> wrote:
>>> As I said, two dictionaries created from the same input will be the
>>> same...
>>
>> That's an implementation detail, not a guarantee.  It will hold for
>> current versions of CPython but not necessarily for other Python
>> implementations.
>
> That day may be sooner than you think. It is very likely that in Python
> 3.3, dict order will be randomized on creation as a side-effect of adding
> a random salt to hashes to prevent a serious vulnerability in dicts.
>
> http://securitytracker.com/id/1026478
>
> http://bugs.python.org/issue13703
>
>
> If there is anyone still assuming that dicts have a predictable order,
> they're going to be in for a nasty surprise one of these days.

The only thing needed to avoid the hash collision is that your hash
function is not not 100% predictable just by looking at the python
source code.  I don't see why every dict would have to be created
differently.  I would think having the most ubiquitous data structure
in your language be more predictable would be a priority.  Oh well....


Nathan



More information about the Python-list mailing list