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

Repr implementation should eval

Open ktbarrett opened this issue 4 years ago • 2 comments

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__.

ktbarrett avatar Jul 25 '19 13:07 ktbarrett

eval is evil...

Marco-Sulla avatar Aug 02 '19 13:08 Marco-Sulla

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

funnydman avatar Dec 07 '19 20:12 funnydman