Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

py.run has import issues on 3.8 #2927

Closed
davidhewitt opened this issue Jan 29, 2023 · 1 comment
Closed

py.run has import issues on 3.8 #2927

davidhewitt opened this issue Jan 29, 2023 · 1 comment

Comments

@davidhewitt
Copy link
Member

davidhewitt commented Jan 29, 2023

The following code crashes on 3.8:

 test_write_unraisable() {
     #[pyfunction]
     fn report_unraisable(py: Python<'_>) {
         use pyo3::exceptions::PyRuntimeError;
         let err = PyRuntimeError::new_err("foo");
         err.write_unraisable(py, None);

         let err = PyRuntimeError::new_err("bar");
         err.write_unraisable(py, Some(py.NotImplemented().as_ref(py)));
     }

     Python::with_gil(|py| {
         let report_unraisable = wrap_pyfunction!(report_unraisable, py).unwrap();
         let locals = PyDict::new(py);
         locals
             .set_item("report_unraisable", report_unraisable)
             .unwrap();

         let source = r#"if True:
         import sys

         captured = []
         def report(data):
             captured.append(list(data))

         original_hook = sys.unraisablehook
         try:
             sys.unraisablehook = report
             report_unraisable()

             assert len(captured) == 2

             assert captured[0][0] is RuntimeError
             assert str(captured[0][1]) == 'foo'
             assert captured[0][4] is None

             assert captured[1][0] is RuntimeError
             assert str(captured[1][1]) == 'bar'
             assert captured[1][4] is NotImplemented
         finally:
             sys.unraisablehook = original_hook
         "#;

         py.run(source, Some(locals), None).unwrap();
     });
 }

(From #2889)

I'm not yet sure what's going on here. Probably worth investigating sometime.

@davidhewitt
Copy link
Member Author

No longer reproduces on main. Probably was fixed by #3378 (thanks @GoldsteinE!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant