python-fire icon indicating copy to clipboard operation
python-fire copied to clipboard

Circular object pointers recurse forever.

Open vlurgio opened this issue 8 years ago • 2 comments

Example:

input code:

In [1]: import jsonpickle

In [2]: a = dict()

In [3]: b = dict()

In [4]: c = dict()

In [5]: a['b'] = b

In [6]: a['c'] = c

In [7]: b['a'] = a

In [8]: b['c'] = c

In [9]: c['b']=b

In [10]: c['a'] = a

In [11]: jsonpickle.encode(a)

output code:

RecursionError Traceback (most recent call last) in () ----> 1 jsonpickle.encode(a)

~/Library/Python/3.6/lib/python/site-packages/jsonpickle/init.py in encode(value, unpicklable, make_refs, keys, max_depth, backend, warn, max_iter, numeric_keys) 130 warn=warn, 131 max_iter=max_iter, --> 132 numeric_keys=numeric_keys) 133 134

~/Library/Python/3.6/lib/python/site-packages/jsonpickle/pickler.py in encode(value, unpicklable, make_refs, keys, max_depth, reset, backend, warn, context, max_iter, numeric_keys) 41 max_iter=max_iter, 42 numeric_keys=numeric_keys) ---> 43 return backend.encode(context.flatten(value, reset=reset)) 44 45

~/Library/Python/3.6/lib/python/site-packages/jsonpickle/pickler.py in flatten(self, obj, reset) 154 if reset: 155 self.reset() --> 156 return self._flatten(obj) 157 158 def _flatten(self, obj):

~/Library/Python/3.6/lib/python/site-packages/jsonpickle/pickler.py in _flatten(self, obj) 158 def _flatten(self, obj): 159 self._push() --> 160 return self._pop(self._flatten_obj(obj)) 161 162 def _flatten_obj(self, obj):

~/Library/Python/3.6/lib/python/site-packages/jsonpickle/pickler.py in _flatten_obj(self, obj) 174 return None 175 --> 176 return flatten_func(obj) 177 178 def _list_recurse(self, obj):

~/Library/Python/3.6/lib/python/site-packages/jsonpickle/pickler.py in _flatten_dict_obj(self, obj, data) 431 flatten = self._flatten_key_value_pair 432 for k, v in sorted(obj.items(), key=util.itemgetter): --> 433 flatten(k, v, data) 434 435 # the collections.defaultdict protocol

~/Library/Python/3.6/lib/python/site-packages/jsonpickle/pickler.py in _flatten_key_value_pair(self, k, v, data) 506 k = unicode(k) 507 --> 508 data[k] = self._flatten(v) 509 return data 510

... last 4 frames repeated, from the frame below ...

~/Library/Python/3.6/lib/python/site-packages/jsonpickle/pickler.py in _flatten(self, obj) 158 def _flatten(self, obj): 159 self._push() --> 160 return self._pop(self._flatten_obj(obj)) 161 162 def _flatten_obj(self, obj):

RecursionError: maximum recursion depth exceeded while calling a Python object

This makes the package almost unusable

vlurgio avatar Aug 01 '18 20:08 vlurgio

I'm not sure whether you meant to put this issue on the jsonpickle github repo, or if I'm just missing the connection to Python Fire. If there is a connection to Python Fire, help me out by pointing it out explicitly?

dbieber avatar Aug 01 '18 21:08 dbieber

Closing since I don't think this is about Python Fire, but please reopen if I was mistaken.

dbieber avatar Aug 03 '18 00:08 dbieber