-
Notifications
You must be signed in to change notification settings - Fork 855
Don't use intocallback in method macros #2664
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
db29cc0
Don't use intocallback in method macros
261058d
Move to impl_/pymethod
2f92ebb
Fix CI
c9d419b
Add newsfragment
a0ca6b3
Only run some tests with some configurations
391a65f
Run some tests only sometimes
ef343f4
Update impl count
cfab15e
Use new trybuild
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PyO3's macros now emit a much nicer error message if function return values don't implement the required trait(s). |
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
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
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
This file was deleted.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,18 @@ | ||
error[E0599]: no method named `assert_into_py_result` found for enum `Result` in the current scope | ||
error[E0277]: the trait bound `PyErr: From<MyError>` is not satisfied | ||
--> tests/ui/invalid_result_conversion.rs:21:1 | ||
| | ||
21 | #[pyfunction] | ||
| ^^^^^^^^^^^^^ method not found in `Result<(), MyError>` | ||
| ^^^^^^^^^^^^^ the trait `From<MyError>` is not implemented for `PyErr` | ||
| | ||
note: the method `assert_into_py_result` exists on the type `()` | ||
--> src/impl_/ghost.rs | ||
| | ||
| fn assert_into_py_result(&mut self) {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= help: the following other types implement trait `From<T>`: | ||
<PyErr as From<&CancelledError>> | ||
<PyErr as From<&IncompleteReadError>> | ||
<PyErr as From<&InvalidStateError>> | ||
<PyErr as From<&LimitOverrunError>> | ||
<PyErr as From<&PanicException>> | ||
<PyErr as From<&PyArithmeticError>> | ||
<PyErr as From<&PyAssertionError>> | ||
<PyErr as From<&PyAttributeError>> | ||
and $N others | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha nice find! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a find, I made it 😉 |
||
= note: required because of the requirements on the impl of `Into<PyErr>` for `MyError` | ||
= note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: use the `?` operator to extract the `()` value, propagating a `Result::Err` value to the caller | ||
| | ||
21 | #[pyfunction]? | ||
| + | ||
|
||
error[E0277]: the trait bound `Result<(), MyError>: IntoPyCallbackOutput<_>` is not satisfied | ||
--> tests/ui/invalid_result_conversion.rs:21:1 | ||
| | ||
21 | #[pyfunction] | ||
| ^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `Result<(), MyError>` | ||
| | ||
= help: the trait `IntoPyCallbackOutput<U>` is implemented for `Result<T, E>` | ||
note: required by a bound in `pyo3::callback::convert` | ||
--> src/callback.rs | ||
| | ||
| T: IntoPyCallbackOutput<U>, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `pyo3::callback::convert` | ||
= note: this error originates in the attribute macro `pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,18 @@ | ||
error[E0599]: the method `assert_into_py_result` exists for struct `Blah`, but its trait bounds were not satisfied | ||
--> tests/ui/missing_intopy.rs:3:1 | ||
| | ||
1 | struct Blah; | ||
| ----------- | ||
| | | ||
| method `assert_into_py_result` not found for this struct | ||
| doesn't satisfy `Blah: IntoPy<Py<PyAny>>` | ||
| doesn't satisfy `Blah: IntoPyResult<Blah>` | ||
2 | | ||
3 | #[pyo3::pyfunction] | ||
| ^^^^^^^^^^^^^^^^^^^ method cannot be called on `Blah` due to unsatisfied trait bounds | ||
| | ||
= note: the following trait bounds were not satisfied: | ||
`Blah: IntoPy<Py<PyAny>>` | ||
which is required by `Blah: IntoPyResult<Blah>` | ||
note: the following trait must be implemented | ||
--> src/conversion.rs | ||
| | ||
| pub trait IntoPy<T>: Sized { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: this error originates in the attribute macro `pyo3::pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0277]: the trait bound `Blah: IntoPyCallbackOutput<_>` is not satisfied | ||
--> tests/ui/missing_intopy.rs:3:1 | ||
| | ||
3 | #[pyo3::pyfunction] | ||
| ^^^^^^^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `Blah` | ||
| | ||
= help: the following other types implement trait `IntoPyCallbackOutput<Target>`: | ||
<() as IntoPyCallbackOutput<()>> | ||
<() as IntoPyCallbackOutput<i32>> | ||
<*mut PyObject as IntoPyCallbackOutput<*mut PyObject>> | ||
<HashCallbackOutput as IntoPyCallbackOutput<isize>> | ||
<IterANextOutput<Py<PyAny>, Py<PyAny>> as IntoPyCallbackOutput<*mut PyObject>> | ||
<IterANextOutput<T, U> as IntoPyCallbackOutput<IterANextOutput<Py<PyAny>, Py<PyAny>>>> | ||
<IterNextOutput<Py<PyAny>, Py<PyAny>> as IntoPyCallbackOutput<*mut PyObject>> | ||
<IterNextOutput<T, U> as IntoPyCallbackOutput<IterNextOutput<Py<PyAny>, Py<PyAny>>>> | ||
and 7 others | ||
note: required by a bound in `pyo3::callback::convert` | ||
--> src/callback.rs | ||
| | ||
| T: IntoPyCallbackOutput<U>, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `pyo3::callback::convert` | ||
= note: this error originates in the attribute macro `pyo3::pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
mejrs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
error[E0277]: the trait bound `Blah: IntoPy<Py<PyAny>>` is not satisfied | ||
--> tests/ui/missing_intopy.rs:3:1 | ||
| | ||
3 | #[pyo3::pyfunction] | ||
| ^^^^^^^^^^^^^^^^^^^ the trait `IntoPy<Py<PyAny>>` is not implemented for `Blah` | ||
| | ||
= help: the following other types implement trait `IntoPy<T>`: | ||
<&'a OsString as IntoPy<Py<PyAny>>> | ||
<&'a Path as IntoPy<Py<PyAny>>> | ||
<&'a PathBuf as IntoPy<Py<PyAny>>> | ||
<&'a PyErr as IntoPy<Py<PyAny>>> | ||
<&'a String as IntoPy<Py<PyAny>>> | ||
<&'a [u8] as IntoPy<Py<PyAny>>> | ||
<&'a str as IntoPy<Py<PyAny>>> | ||
<&'a str as IntoPy<Py<PyString>>> | ||
and $N others | ||
= note: required because of the requirements on the impl of `OkWrap<Blah>` for `Blah` | ||
= note: this error originates in the attribute macro `pyo3::pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info) |
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.
Uh oh!
There was an error while loading. Please reload this page.