Raymond Hettinger <[email protected]> added the comment:
This isn't a bug because the MappingProxy doesn't promise to do early detection
and because it can't really be accomplished cleanly.
Perfect detection of non-mappings isn't possible. Some easy, minimal checks
are made for early detection using PyMapping_Check, PyList_Check, and
PyTuple_Check. Anything that gets past those checks will just need to be
duck-typed downstream when it is used.
We could add a few other specific exclusions but that isn't a general solution
and it slows down instantiation. Further it could break code that is intended
to work (subclasses of str that mapping methods) or that just happen to work:
>>> from types import MappingProxyType
>>> mp = MappingProxyType('abc')
>>> mp[0]
'a'
----------
nosy: +rhettinger
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43828>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com