[ADD] P3: hash randomisation docs

This commit is contained in:
Xavier Morel
2017-06-12 11:04:23 +02:00
parent 4957296f1d
commit 5654a1ab95
+31
View File
@@ -61,6 +61,35 @@ features whereas:
generator delegation, pathlib, ...), you must *not *use them in Odoo
until Python 2 support is dropped
Semantics changes
=================
Dict & set iteration order ("Hash Randomisation")
-------------------------------------------------
In Python 2, the iteration order depends on the value's hash (modulo the
collection's capacity and conflict resolution), which provides a
spec-undefined but implementation-defined order. While that's not supposed to
happen, it turns out code may depend on the specific order of iteration over
a hash collection (``dict`` or ``set``).
Python 3.3 enables `hash randomisation`_ by default (this can be optionally
enabled on previous versions including Python 2 by providing the ``-R``
command-line parameter), which means *the order of iteration changes from one
run to the next*.
When discovered, this can be fixed by one of:
* making iteration steps properly independent (removing the dependency of
order of iteration)
* using different checking method (e.g. when serialising sets or dictionaries
and checking against the specific serialised value)
* fixing dependencies
* using a ``collections.OrderedDict`` or ``odoo.tools.misc.OrderedSet`` instead
of a regular one, they guarantee order of iteration is order of insertion
* sorting the collection's items before iterating over them (this may require
adding some sort of iteration key to the items)
Moved and removed
=================
@@ -340,6 +369,8 @@ Minor syntax changes
error, octal literals now follow the hexadecimal convention with a ``0o``
prefix.
.. _hash randomisation: http://bugs.python.org/issue13703
.. _requests: http://docs.python-requests.org/
.. _werkzeug: http://werkzeug.pocoo.org/docs/urls/