You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Have you tried using latest PyO3 master (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: Yes
💥 Reproducing
Create a custom object #[pyclass], let's call it MyClass.
Try to use &MyClass as a function argument in a #[pyproto] block:
use pyo3::prelude::*;
use pyo3::basic::{CompareOp, PyObjectProtocol};
#[pyclass]
pub struct MyClass {}
#[pyproto]
impl PyObjectProtocol for MyClass {
fn __richcmp__(&self, other: &MyClass, op: CompareOp) -> PyResult<()> {
unimplemented!()
}
}
This will fail to compile:
error[E0277]: the trait bound `&MyClass: pyo3::pyclass::PyClass` is not satisfied
--> src\lib.rs:7:1
|
7 | #[pyproto]
| ^^^^^^^^^^ the trait `pyo3::pyclass::PyClass` is not implemented for `&MyClass`
|
::: C:\Users\david\dev\pyo3\src\class\basic.rs:140:17
|
140 | type Other: FromPyObject<'p>;
| ---------------- required by this bound in `pyo3::class::basic::PyObjectRichcmpProtocol`
|
= help: the following implementations were found:
<MyClass as pyo3::pyclass::PyClass>
= note: required because of the requirements on the impl of `pyo3::conversion::FromPyObject<'p>` for `&MyClass`
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
I expect this broke on 0.9.0 when we changed so that &PyClass implements derive_utils::ExtractExt instead of FromPyObject.
cc @kngwyu - I guess that when you refactor protocol methods to remove specialization this problem might automatically be fixed at the same time. It could be interesting to add a test for it then.
The text was updated successfully, but these errors were encountered:
I don't think it's possible. Users can use &PyRef instead.
To enable this, we need a more complex trait that can represent T: FromPyObject or U: FromPyObject, U: Deref<Target = T>.
I guess that when you refactor protocol methods to remove specialization this problem might automatically be fixed at the same time.
🌍 Environment
0.10.1
version = "0.x.y"
withgit = "https://github.com/PyO3/pyo3")?
: Yes💥 Reproducing
Create a custom object
#[pyclass]
, let's call itMyClass
.Try to use
&MyClass
as a function argument in a#[pyproto]
block:This will fail to compile:
I expect this broke on
0.9.0
when we changed so that&PyClass
implementsderive_utils::ExtractExt
instead ofFromPyObject
.cc @kngwyu - I guess that when you refactor protocol methods to remove specialization this problem might automatically be fixed at the same time. It could be interesting to add a test for it then.
The text was updated successfully, but these errors were encountered: