with self.cursor() as cursor:
# two frames, accounting for execute() and @contextmanager
locals = inspect.currentframe(depth + 2).f_locals
- cursor.execute(statement.format(**locals), locals)
+ try:
+ cursor.execute(statement.format(**locals), locals)
+ finally:
+ del locals
yield cursor
@contextmanager