-
Notifications
You must be signed in to change notification settings - Fork 748
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
"TypeError: No constructor defined" discards exception context #3432
Labels
Comments
We could fix this by setting the
Unfortunately this only works on Python 3.10 and up :(. |
Potentially we can use that on 3.10 and up and reverse engineer a similar implementation for the older pythons? I think moving to a solution managed by the runtime is much cleaner overall. |
This was referenced Sep 9, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Description
PyO3 raises
TypeError
when you try to construct a#[pyclass]
without a constructor. The raised exception doesn't have a value for the__context__
attribute, which breaks exception chaining. This is especially problematic when implementing a custom exception from Rust.pyo3/src/pyclass/create_type_object.rs
Lines 438 to 449 in bf093b3
Steps to Reproduce
PyO3 module:
Test cases:
Only the
RustException
test case fails.Backtrace
Your operating system and version
Windows 11
Your Python version (
python --version
)Python 3.11.0
Your Rust version (
rustc --version
)rustc 1.70.0 (90c541806 2023-05-31)
Your PyO3 version
0.19.0
How did you install python? Did you use a virtualenv?
Standard Windows installer. I used a venv.
Additional Info
I ran into this issue with Pydantic's ValidationError type, which doesn't have a constructor. This issue has more details on that particular use case: pypa/hatch#959
The text was updated successfully, but these errors were encountered: