Best practise implementation for equal by value objects

Slaunger Slaunger at gmail.com
Fri Aug 8 03:07:12 EDT 2008


On 7 Aug., 21:25, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Terry Reedy <tjre... 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.

Thank you for pointing out the dangers of eval. I think you are right
to
caution about it. In my particular case it is a closed-loop system, so
no
danger there, but that certainly could have been an issue.

That caution should perhaps be mentioned in
http://docs.python.org/lib/built-in-funcs.html



More information about the Python-list mailing list