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 Michael Smith2
Recipients Michael Smith2, bob.ippolito, rhettinger
Date 2018-10-02.03:01:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1538449296.36.0.545547206417.issue34858@psf.upfronthosting.co.za>
In-reply-to
Content
OK, I appreciate the response. The MappingProxy objects I am working with are in a nested data structure, so accessing them to coerce them directly isn't feasible. I created 

class MappingProxyEncoder(JSONEncoder):
  def default(self, obj):
    if isinstance(obj, MappingProxyType):
      return obj.copy()
    return JSONEncoder.default(self, obj)

and using that works fine for json.dumps (passes all my tests, at least). But I suspect that obj.copy() is more expensive than the code I'm replacing, which is a local implementation of ImmutableDict I was trying to do away with, following a readthrough of PEP 416. I wonder if there's a cheaper way to get at the underlying dictionary.

I suspect I'm not the only python user who foolishly expected MappingProxy to be a drop-in replacement for local ImmutableDict implementations. Maybe this ticket will be useful for others to read.
History
Date User Action Args
2018-10-02 03:01:36Michael Smith2setrecipients: + Michael Smith2, rhettinger, bob.ippolito
2018-10-02 03:01:36Michael Smith2setmessageid: <1538449296.36.0.545547206417.issue34858@psf.upfronthosting.co.za>
2018-10-02 03:01:36Michael Smith2linkissue34858 messages
2018-10-02 03:01:35Michael Smith2create