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.

Author rhettinger
Recipients andymaier, rhettinger
Date 2021-04-14.03:09:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1618369749.33.0.0570221783503.issue43828@roundup.psfhosted.org>
In-reply-to
Content
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'
History
Date User Action Args
2021-04-14 03:09:09rhettingersetrecipients: + rhettinger, andymaier
2021-04-14 03:09:09rhettingersetmessageid: <1618369749.33.0.0570221783503.issue43828@roundup.psfhosted.org>
2021-04-14 03:09:09rhettingerlinkissue43828 messages
2021-04-14 03:09:09rhettingercreate