bidict/docs/caveat-nan-as-key.rst.inc

27 lines
760 B
PHP

.. _nan-as-key:
nan As Key
^^^^^^^^^^
`In CPython <http://doc.pypy.org/en/latest/cpython_differences.html>`_,
nan is especially tricky when used as a dictionary key::
>>> d = {float('nan'): 'nan'}
>>> d
{nan: 'nan'}
>>> d[float('nan')] # doctest: +SKIP
Traceback (most recent call last):
...
KeyError: nan
>>> d[float('nan')] = 'not overwritten'
>>> d # doctest: +SKIP
{nan: 'nan', nan: 'not overwritten'}
In other Python implementations such as PyPy,
nan behaves just like any other dictionary key.
But in CPython, beware of this unexpected behavior,
which applies to bidicts too.
bidict contains no special-case logic
for dealing with nan as a key,
so the behavior will match dict's in the host environment.