Skip to content
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

Allow user defined exceptions to have docstrings #2027

Merged
merged 4 commits into from Dec 14, 2021

Conversation

mejrs
Copy link
Member

@mejrs mejrs commented Nov 26, 2021

For #2016

src/err/mod.rs Outdated Show resolved Hide resolved
@mejrs
Copy link
Member Author

mejrs commented Nov 29, 2021

I don't know why this error occurs only on certain platforms:
Error: PyErr { type: <class 'NameError'>, value: NameError("name 'str' is not defined"), traceback: Some(<traceback object at 0x0000022BD1373448>) }.

while running

/// # fn main() -> PyResult<()> {
/// #     Python::with_gil(|py| -> PyResult<()> {
/// #         let fun = wrap_pyfunction!(raise_myerror, py)?;
/// #         let globals = pyo3::types::PyDict::new(py);
/// #         globals.set_item("MyError", py.get_type::<MyError>())?;
/// #         globals.set_item("raise_myerror", fun)?;
/// #
/// #         py.run(
/// # "try:
/// #     raise_myerror()
/// # except MyError as e:
/// #     assert e.__doc__ == 'Some description.'
/// #     assert str(e) == 'Some error happened.'",
/// #             Some(globals),
/// #             None,
/// #         )?;
/// #
/// #         Ok(())
/// #     })
/// # }

@davidhewitt
Copy link
Member

Sorry it took me a while to get to this, thanks for implementing! Got a few ideas and comments r.e. the new_type stuff

src/exceptions.rs Show resolved Hide resolved
src/err/mod.rs Outdated Show resolved Hide resolved
src/exceptions.rs Outdated Show resolved Hide resolved
src/err/mod.rs Outdated Show resolved Hide resolved
@mejrs
Copy link
Member Author

mejrs commented Dec 4, 2021

I have combined the functions and made it return Result<Py<PyType>>. I think this is good to go after the 1.57 changes merge.

@davidhewitt
Copy link
Member

Sorry for the catastrophically slow reviewing. Looks great to me! Just needs rebasing and a CHANGELOG entry :)

@mejrs
Copy link
Member Author

mejrs commented Dec 14, 2021

Sorry for the catastrophically slow reviewing. Looks great to me! Just needs rebasing and a CHANGELOG entry :)

Should be good to go now :)

Copy link
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.

Perfect, thanks again!

@davidhewitt davidhewitt merged commit 397555f into PyO3:main Dec 14, 2021
@9999years
Copy link

Any chance we could cut a release with this feature? I forked pyo3 to add this but it's already here, just unreleased.

@davidhewitt
Copy link
Member

@9999years please follow #2079 - we're getting close to last piece we want to complete before next release lands. You might be able to use a git dependency in the meanwhile?

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.

Allow adding docstrings to the classes created with create_exception!
3 participants