[New-bugs-announce] [issue32899] Not documented: key in dict test may raise TypeError

xitop report at bugs.python.org
Wed Feb 21 15:01:23 EST 2018


New submission from xitop <reg.bugs at poti.sk>:

I'd like to suggest an addition to the documentation of the "key in dict" operation.

Current version found at
https://docs.python.org/3/library/stdtypes.html#dict
says only:

---
key in d

    Return True if d has a key key, else False.
---

This is not precise. TypeError is also a possible outcome. It happens when the key is unhashable. Unsure whether the description is incomplete or the membership test has a bug I submitted the issue 32675 in January. The issue was closed with resolution of "not a bug".

If it is indded the intended behaviour, I think it needs to be documented in order to prevent further misunderstandings. Before the issue 32675 I believed a membership test is failsafe, because the definition of __contains__ clearly defines the return value as either True or False.

----------
assignee: docs at python
components: Documentation
messages: 312506
nosy: docs at python, xitop
priority: normal
severity: normal
status: open
title: Not documented: key in dict test may raise TypeError
type: enhancement

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


More information about the New-bugs-announce mailing list