Skip to content

feat: add From conversions for standard library errors#6001

Merged
davidhewitt merged 2 commits intoPyO3:mainfrom
Harikeshav-R:feat/add-std-error-conversions
Apr 29, 2026
Merged

feat: add From conversions for standard library errors#6001
davidhewitt merged 2 commits intoPyO3:mainfrom
Harikeshav-R:feat/add-std-error-conversions

Conversation

@Harikeshav-R
Copy link
Copy Markdown
Contributor

This PR adds missing From conversions to PyErr (mapping to Python's ValueError) for several straightforward standard library errors.

The added conversions include:

  • std::time::TryFromFloatSecsError
  • std::time::SystemTimeError
  • std::path::StripPrefixError
  • std::env::JoinPathsError
  • std::char::ParseCharError
  • std::char::CharTryFromError

As discussed in the issue, conversions for std::string::FromUtf16Error, std::char::DecodeUtf16Error, and std::env::VarError have been intentionally omitted as they are non-trivial or were previously removed.

Resolves #5993.

Copilot AI review requested due to automatic review settings April 24, 2026 19:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>PyErr conversions for 6 additional std error types via the existing impl_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.

Comment thread src/err/impls.rs Outdated
Copy link
Copy Markdown
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@davidhewitt davidhewitt added this pull request to the merge queue Apr 29, 2026
Merged via the queue into PyO3:main with commit af49fe5 Apr 29, 2026
44 of 45 checks passed
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
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

Successfully merging this pull request may close these issues.

PyErr conversion for TryFromFloatSecsError (and other missing stdlib errors?)

3 participants