I don't think an eval is very idiomatic.  A callback function would be better, and I think a context manager for a `with` statement would be idiomatic.