[pypy-issue] Issue #2029: lambdas not is not JSON serializable (pypy/pypy)

gjvc issues-reply at bitbucket.org
Tue Apr 14 01:54:41 CEST 2015


New issue 2029: lambdas not is not JSON serializable
https://bitbucket.org/pypy/pypy/issue/2029/lambdas-not-is-not-json-serializable

gjvc:

This code runs fine in CPython 2.7, but not in pypy


```
#!python

#! /usr/bin/env python

import collections
import json


class objdict( collections.defaultdict ):

    def __getattr__( self, key ):
        try:
            return self.__dict__[ key ]
        except KeyError:
            return self.__getitem__( key )

    __setattr__ = lambda self, key, value: self.__setitem__( key, value )

def objtree():
    return objdict(objtree)


obj = objtree()
print json.dumps( obj, indent=4 )
obj.x.y.z = 4
print json.dumps( obj, indent=4 )
obj.x.y = 3
print json.dumps( obj, indent=4 )
obj.x = 2
print json.dumps( obj, indent=4 )
del obj[ 'x' ]
print json.dumps( obj, indent=4 )

```





More information about the pypy-issue mailing list