Python closures and stack frames