-
Notifications
You must be signed in to change notification settings - Fork 792
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
Implement eyre
feature
#1893
Implement eyre
feature
#1893
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks great! Should we merge this at the same time as #1822 ?
Cargo.toml
Outdated
# must stay at 0.3.x for Rust 1.41 compatibility | ||
eyre = {version = ">= 0.4" , optional = true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think these need to be swapped (new dep has split comment from its target). Also, should we place an upper bound?
# must stay at 0.3.x for Rust 1.41 compatibility | |
eyre = {version = ">= 0.4" , optional = true} | |
eyre = {version = ">= 0.4, <0.5" , optional = true} | |
# must stay at 0.3.x for Rust 1.41 compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(oops)
Eyre is at 0.6.5 now, so that upper bound is too strict. 0.4 is the first version that has the eyre::Report type (?), so I think any version above that should be fine.
I'll admit that I don't know anything about how cargo resolves dependency versions, but this looks like how you should say "works with any eyre version of 0.4 and up". Is that too liberal and should it be pinned to ">= 0.4, <0.7"
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that by default cargo
will pick the highest eyre
possible for the pyo3 dependency, not the one which the user already has in their own Cargo.toml. (This is a bit awkward.) The user can adjust it manually using some incantation of cargo update --precise
(like we do in our MSRV CI jobs).
Is that too liberal and should it be pinned to
">= 0.4, <0.7"
instead?
Generally we've only offered a range for dependencies when the MSRV support requires an older version. I'd be tempted to ask the other question - is just supporting eyre = "0.6"
acceptable?
As for the upper bound: if we were to take semver literally, eyre 0.7
could hypothetically be very breaking and completely remove the eyre::Report
type. (Although I would be suprised if this happened in practice.) So I'd definitely prefer have an upper bound of < 0.7
if we go for a range. Dependabot can remind us to update when 0.7 releases 😄
src/conversions/eyre.rs
Outdated
//! // A wrapper around a Rust function. | ||
//! #[pyfunction] | ||
//! fn py_open(filename: PathBuf) -> PyResult<Vec<u8>> { | ||
//! // The `?` ("try") operator performs the conversion | ||
//! // into a `PyErr` - if it is an error. | ||
//! let data = rust_open(filename)?; | ||
//! Ok(data) | ||
//! } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be possible to also just have a #[pyfunction]
which returns eyre::Result<Vec<u8>>
- which might be useful to have as an example (as a kind of test)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about doing that but I want to point at the where the conversion happens. A #[pyfunction]
returning eyre::Result<Vec<u8>>
has that conversion hidden somewhere in the pyfunction
macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a fair point. I wonder if your second example "using eyre
in general" could be tweaked slightly so that the function decompress
is a pyfunction
returning eyre::Result
? The conversion from PyErr
-> eyre::Result
can still be there.
Alternatively maybe it's better to keep away from that here, and instead in the guide's function.md
there is probably scope for an improved "error handling" section which comments on how to use Result
with error types that convert to PyErr
. (And can use Result<_, eyre::Report>
as an example?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I do want a pyfunction returning eyre's error. I think it is too easy for readers to assume that a pyfunction must return a PyResult and they have to wrap functions. I'm not sure if that was your reasoning though.
I do want to expand the error handling in the guide, but not with this PR.
Oh, also this is definitely worth a CHANGELOG line :) |
CHANGELOG.md
Outdated
- Add `abi3-py310` feature. [#1889](https://github.com/PyO3/pyo3/pull/1889) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bonus newline!
CHANGELOG.md
Outdated
@@ -22,8 +22,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
- Add `PyMapping` type to represent the Python mapping protocol. [#1844](https://github.com/PyO3/pyo3/pull/1844) | |||
- Add commonly-used sequence methods to `PyList` and `PyTuple`. [#1849](https://github.com/PyO3/pyo3/pull/1849) | |||
- Add `as_sequence` methods to `PyList` and `PyTuple`. [#1860](https://github.com/PyO3/pyo3/pull/1860) | |||
- Add `eyre` feature to convert `eyre::report` into `PyErr`. [#1893](https://github.com/PyO3/pyo3/pull/1893) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Add `eyre` feature to convert `eyre::report` into `PyErr`. [#1893](https://github.com/PyO3/pyo3/pull/1893) | |
- Add `eyre` feature to convert `eyre::Report` into `PyErr`. [#1893](https://github.com/PyO3/pyo3/pull/1893) |
Also for dependencies I quite like to have something in the Packaging
section along the lines of "added optional eyre
dependency" - what do you think of having that as well (or instead)?
Cargo.toml
Outdated
# must stay at 0.3.x for Rust 1.41 compatibility | ||
eyre = {version = ">= 0.4" , optional = true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that by default cargo
will pick the highest eyre
possible for the pyo3 dependency, not the one which the user already has in their own Cargo.toml. (This is a bit awkward.) The user can adjust it manually using some incantation of cargo update --precise
(like we do in our MSRV CI jobs).
Is that too liberal and should it be pinned to
">= 0.4, <0.7"
instead?
Generally we've only offered a range for dependencies when the MSRV support requires an older version. I'd be tempted to ask the other question - is just supporting eyre = "0.6"
acceptable?
As for the upper bound: if we were to take semver literally, eyre 0.7
could hypothetically be very breaking and completely remove the eyre::Report
type. (Although I would be suprised if this happened in practice.) So I'd definitely prefer have an upper bound of < 0.7
if we go for a range. Dependabot can remind us to update when 0.7 releases 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, all looks really good. Sorry for the delay - I was ill over the weekend. Feeling a bit more capable this morning finally!
Just commented on the remaining points with some thoughts. All is great as-is though so also happy if you want to call this done for now and merge it!
//! let text = decompress(bytes)?; | ||
//! | ||
//! println!("The text is \"{}\"", text); | ||
//! # assert_eq!(text, "You should probably use the libflate crate instead."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😂
src/conversions/eyre.rs
Outdated
//! // A wrapper around a Rust function. | ||
//! #[pyfunction] | ||
//! fn py_open(filename: PathBuf) -> PyResult<Vec<u8>> { | ||
//! // The `?` ("try") operator performs the conversion | ||
//! // into a `PyErr` - if it is an error. | ||
//! let data = rust_open(filename)?; | ||
//! Ok(data) | ||
//! } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a fair point. I wonder if your second example "using eyre
in general" could be tweaked slightly so that the function decompress
is a pyfunction
returning eyre::Result
? The conversion from PyErr
-> eyre::Result
can still be there.
Alternatively maybe it's better to keep away from that here, and instead in the guide's function.md
there is probably scope for an improved "error handling" section which comments on how to use Result
with error types that convert to PyErr
. (And can use Result<_, eyre::Report>
as an example?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks! Feel free to merge this at your will (at the same time as finishing up #1822?)
Co-authored-by: David Hewitt <[email protected]>
I don't see a reason to let this sit around here. I think we'd still want to have them both in 0.15 though. |
Per eyre-rs/eyre#57