New submission from xitop <reg.b...@poti.sk>: The `dict.__contains()` function does not fully comply with the description in the "Data Model" section of the official documentation, which states: "__contains__(self, item) ... Should return true if item is in self, false otherwise."
Basically the same is written in "Mapping Types - dict": "key in d - Return True if d has a key key, else False." According to that, testing a presence of an unhashable object in a dict should return False. But it raises a TypeError instead. Example: >>> () in {} False but: >>> [] in {} Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'list' There is a related SO question: https://stackoverflow.com/questions/48444079/unexpected-behaviour-of-dictionary-membership-check currently without a clear answer whether it is a bug or desired behaviour supposed to expose programming errors. In the latter case, it seems to be not documented. ---------- components: Interpreter Core messages: 310751 nosy: xitop priority: normal severity: normal status: open title: dict.__contains__(unhashable) raises TypeError where False was expected versions: Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32675> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com