forked from PyO3/pyo3
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request PyO3#3260 from mejrs/traverse
Give a better error message for Python argument in __traverse__
- Loading branch information
Showing
6 changed files
with
64 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 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 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,27 @@ | ||
use pyo3::prelude::*; | ||
use pyo3::PyVisit; | ||
use pyo3::PyTraverseError; | ||
|
||
#[pyclass] | ||
struct TraverseTriesToTakePyRef {} | ||
|
||
#[pymethods] | ||
impl TraverseTriesToTakePyRef { | ||
fn __traverse__(slf: PyRef<Self>, visit: PyVisit) {} | ||
} | ||
|
||
#[pyclass] | ||
struct Class; | ||
|
||
#[pymethods] | ||
impl Class { | ||
fn __traverse__(&self, py: Python<'_>, visit: PyVisit<'_>) -> Result<(), PyTraverseError> { | ||
Ok(()) | ||
} | ||
|
||
fn __clear__(&mut self) { | ||
} | ||
} | ||
|
||
|
||
fn main() {} |
This file contains 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,23 @@ | ||
error: __traverse__ may not take `Python`. Usually, an implementation of `__traverse__` should do nothing but calls to `visit.call`. Most importantly, safe access to the GIL is prohibited inside implementations of `__traverse__`, i.e. `Python::with_gil` will panic. | ||
--> tests/ui/traverse.rs:18:32 | ||
| | ||
18 | fn __traverse__(&self, py: Python<'_>, visit: PyVisit<'_>) -> Result<(), PyTraverseError> { | ||
| ^^^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> tests/ui/traverse.rs:9:6 | ||
| | ||
8 | #[pymethods] | ||
| ------------ arguments to this function are incorrect | ||
9 | impl TraverseTriesToTakePyRef { | ||
| ______^ | ||
10 | | fn __traverse__(slf: PyRef<Self>, visit: PyVisit) {} | ||
| |___________________^ expected fn pointer, found fn item | ||
| | ||
= note: expected fn pointer `for<'a, 'b> fn(&'a TraverseTriesToTakePyRef, PyVisit<'b>) -> Result<(), PyTraverseError>` | ||
found fn item `for<'a, 'b> fn(pyo3::PyRef<'a, TraverseTriesToTakePyRef>, PyVisit<'b>) {TraverseTriesToTakePyRef::__traverse__}` | ||
note: function defined here | ||
--> src/impl_/pymethods.rs | ||
| | ||
| pub unsafe fn call_traverse_impl<T>( | ||
| ^^^^^^^^^^^^^^^^^^ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.