Bug Description
Passing Some(_) as globals to py.run() breaks Python builtins under Python 3.8 and 3.9 (and maybe others, but not 3.10).
Steps to Reproduce
Run the following code (linking with Python 3.8 or Python 3.9):
fn main() -> eyre::Result<()> {
let script_text = r#"
def trivial(s):
return s
class Foo:
def __init__(self):
print(trivial('Hello, world!'))
"#;
pyo3::Python::with_gil(|py| {
let module = pyo3::types::PyDict::new(py);
py.run(script_text, Some(module), Some(module))?;
let foo_class = module.get_item("Foo").unwrap();
let _foo = foo_class.call0()?;
Ok(())
})
}
Observe the following error:
NameError: __build_class__ not found
Your operating system and version
NixOS
Your Python version (python --version)
Python 3.8.17, Python 3.9.17
Your Rust version (rustc --version)
rustc 1.73.0-nightly (8131b9774 2023-08-02)
Your PyO3 version
0.19.2
How did you install python? Did you use a virtualenv?
Nix, no virtualenv
Additional Info
Possibly related to #3371, #2891