-
Notifications
You must be signed in to change notification settings - Fork 930
Description
Bug Description
Getting an unexpected TypeError with strange message when converting Rust's FromUtf8Error to Python's UnicodeDecodeError. Not sure if other error/exception types are also affected, I haven't had a chance to check more thoroughly.
Steps to Reproduce
Using a simple function to create a Rust FromUtf8Error:
#[pyfunction]
fn unicode_error() -> PyResult<String> {
Ok(String::from_utf8(b"\xff".to_vec())?)
}From Python:
>>> unicode_error()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function takes exactly 5 arguments (1 given)
Normalization failed: type=UnicodeDecodeError args='invalid utf-8 sequence of 1 bytes from index 0'
>>>I expected to get the UnicodeDecodeError, instead getting a message (presumably) about PyO3 failing to construct the UnicodeDecodeError.
Backtrace
Your operating system and version
Ubuntu 24.04
Your Python version (python --version)
Python 3.12.3
Your Rust version (rustc --version)
rustc 1.89.0 (29483883e 2025-08-04)
Your PyO3 version
0.27.1
How did you install python? Did you use a virtualenv?
Installed Python through apt
Using a virtualenv and Maturin
Additional Info
No response
Metadata
Metadata
Assignees
Labels
No labels