types.MappingProxyType states that proxy[key] will throw a KeyError, but that is not always true
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Documentation
In the documentation, it states proxy[key] will:
Return the item of the underlying mapping with key key. Raises a KeyError if key is not in the underlying mapping.
https://docs.python.org/3/library/types.html#types.MappingProxyType
However, it is possible to get an AttributeError instead, and in fact, unit tests for the dataclasses module require this to be true (metadata in dataclasses.field is wrapped in a mapping proxy):
The unit tests above are from Python3.12.
Looks like the CPython source code only forwards the getitem call to the inner mapping:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the MappingProxyType documentation at the linked Python docs page, then compare its wording with the referenced dataclasses tests and Objects/descrobject.c implementation. Done means the documentation accurately describes the exception behavior demonstrated by the tests and implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100