slezica / python-frozendict

A simple immutable mapping for python
MIT License
111 stars 22 forks source link

Repr implementation should eval #28

Open ktbarrett opened 5 years ago

ktbarrett commented 5 years ago

All builtin types have a __repr__ implementation that can be fed to eval to obtain the original Python value. This is on purpose. frozendict and OrderedFrozendict simply being an immutable version of builtin types should also support this behavior. One simply need to slightly modify the __repr__ implementation.

def __repr__(self):
        return '%s(%r)' % (self.__class__.__name__, self._dict)

This parallels frozenset's __repr__.

Marco-Sulla commented 5 years ago

eval is evil...

funnydman commented 4 years ago

@Marco-Sulla agree, but sometimes it can be handy, not sure about this case though.