feat: add From conversions for standard library errors#6001
Merged
davidhewitt merged 2 commits intoPyO3:mainfrom Apr 29, 2026
Merged
feat: add From conversions for standard library errors#6001davidhewitt merged 2 commits intoPyO3:mainfrom
davidhewitt merged 2 commits intoPyO3:mainfrom
Conversation
0a7b10c to
90dbd5e
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds missing From conversions to PyErr for several standard library error types, mapping them to Python’s ValueError and validating the conversions via unit tests.
Changes:
- Implement
From<T>→PyErrconversions for 6 additionalstderror types via the existingimpl_to_pyerr!macro. - Add a new unit test covering these conversions and asserting error type/message behavior.
- Add a towncrier newsfragment documenting the new conversions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/err/impls.rs |
Adds impl_to_pyerr! mappings for additional stdlib errors and a test validating conversion output. |
newsfragments/9999.added.md |
Documents the new conversions in release notes (towncrier fragment). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ueError for consistency
davidhewitt
pushed a commit
to davidhewitt/pyo3
that referenced
this pull request
May 1, 2026
* feat: add From conversions for standard library errors * fix: use exceptions::PyValueError instead of crate::exceptions::PyValueError for consistency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds missing
Fromconversions toPyErr(mapping to Python'sValueError) for several straightforward standard library errors.The added conversions include:
std::time::TryFromFloatSecsErrorstd::time::SystemTimeErrorstd::path::StripPrefixErrorstd::env::JoinPathsErrorstd::char::ParseCharErrorstd::char::CharTryFromErrorAs discussed in the issue, conversions for
std::string::FromUtf16Error,std::char::DecodeUtf16Error, andstd::env::VarErrorhave been intentionally omitted as they are non-trivial or were previously removed.Resolves #5993.