Best practise implementation for equal by value objects
Thu Aug 7 21:25:11 CEST 2008
Terry Reedy <tjreedy at udel.edu> writes:
> So when the initializers for instances are all 'nice' (as for range),
> go for it (as in 'Age(10)'). And test it as you are by eval'ing the
> rep. Just accept that the eval will only work in contexts with the
> class name bound to the class. For built-in like range, it always is,
> by default -- unless masked by another assignment!
Eval is extremely dangerous. Think of data from untrusted sources,
then ask yourself how well you really know where ALL your data came
from. It's preferable to avoid using it that way. There have been a
few "safe eval" recipes posted here and at ASPN. It would be good if
one of them made it into the standard library. Note that pickle
(which would otherwise be an obious choice for this) has the same
problems, though not as severely as flat-out evalling something.
More information about the Python-list