inveniosoftware / dojson

Simple pythonic JSON to JSON converter.
https://dojson.readthedocs.io
Other
10 stars 29 forks source link

utils: eval(repr(GroupableOrderedDict(...)) != GroupableOrderedDict(...) #162

Closed kaplun closed 8 years ago

kaplun commented 8 years ago

Currently:

>>> from dojson.utils import GroupableOrderedDict
>>> a = GroupableOrderedDict((('a', 12), ('b', 123), ('a', 23)))
>>> repr(a)
"GroupableOrderedDict((('__order__', ('a', 'b', 'a')), ('a', (12, 23)), ('b', 123)))"
>>> eval(repr(a))
GroupableOrderedDict([('__order__',
                       ('__order__', '__order__', '__order__', 'a', 'a', 'b')),
                      ('a', (12, 23)),
                      ('b', 123)])
>>> eval(repr(a)) == a
False

instead I would expect:

>>> repr(a)
"GroupableOrderedDict((('a', 12), ('b', 123), ('a', 23)))"
>>> eval(repr(a))
GroupableOrderedDict((('a', 12), ('b', 123), ('a', 23)))
>>> eval(repr(a)) == a
True

See: https://docs.python.org/2/library/functions.html#repr