Skip to content

Conversation

@davidhewitt
Copy link
Member

This PR carries out a small cleanup I noted while reading the error implementation recently.

The error handling code had logic to handle panics and missing exceptions inline in the functions. I pull this all out into separate #[cold] functions so that the happy paths are as lean as possible.

src/err/mod.rs Outdated
fn failed_to_fetch() -> PyErr {
const FAILED_TO_FETCH: &str = "attempted to fetch exception but none was set";

#[cfg(debug_assertions)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Hyper-nit: might be slightly more readable with a if cfg!:

if cfg!(debug_assertions) {
    panic!("{}", FAILED_TO_FETCH)
} else {
    crate::exceptions::PySystemError::new_err(FAILED_TO_FETCH)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I like it, good idea 👍

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Nov 29, 2025
@davidhewitt davidhewitt added this pull request to the merge queue Nov 29, 2025
Merged via the queue into PyO3:main with commit 545a527 Nov 29, 2025
42 of 43 checks passed
@davidhewitt davidhewitt deleted the fast-path-errors branch November 29, 2025 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-skip-changelog Skip checking changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants