This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: OrderedDict behavior is unclear with misbehaving keys.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: eric.snow Nosy List: eric.snow, rhettinger, superluser
Priority: normal Keywords:

Created on 2015-06-03 03:01 by eric.snow, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg244727 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2015-06-03 03:01
How well does OrderedDict need to behave in the face of keys with unstable hashes (e.g. define __hash__ with varying results across calls)?  I would expect the behavior to be undefined (though non-crashing).  Here's an example of a misbehaving key:

    class Key:
        def __hash__(self):
            return randrange(10000)

FWIW, dict does pretty well even with bad keys.  The pure Python OrderedDict does okay.
msg245544 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-06-20 06:53
>  I would expect the behavior to be undefined (though non-crashing).

That is all you should expect.
msg248072 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2015-08-05 20:16
Fair enough.
History
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68558
2015-08-05 20:16:44eric.snowsetstatus: open -> closed
resolution: not a bug
messages: + msg248072

stage: needs patch -> resolved
2015-06-20 06:53:13rhettingersetmessages: + msg245544
2015-06-20 01:58:59superlusersetnosy: + superluser
2015-06-03 03:01:20eric.snowcreate