[issue45054] json module should issue warning about duplicate keys

Raymond Hettinger report at bugs.python.org
Sat Nov 13 20:10:43 EST 2021


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

-0 on doing this. The suggested warning/error adds overhead that everyone would pay for but would almost never be of benefit.  I haven't seen this particular problem arise in practice.  The likely reasons it doesn't come up are 1) that generated data doesn't normally produce mixed type keys, 2) because mixed type keys don't round-trip, and 3) even using numeric keys only (not mixed) is uncommon because it results in poor outcomes that fail round-trip invariants.

Andrei Kulakov is right in saying that such data suggests deeper problems with the design and that static typing would be beneficial.

One last thought:  Even with regular dicts, we don't normally warn about encountering duplicate keys:

    >>> dict([(1, 'run'), (1, 'zoo'), (3, 'tree')])
    {1: 'zoo', 3: 'tree'}

----------
nosy: +rhettinger

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45054>
_______________________________________


More information about the Python-bugs-list mailing list