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

Property methods cannot take self as a PyRef #837

Closed
thequux opened this issue Mar 26, 2020 · 1 comment · Fixed by #999
Closed

Property methods cannot take self as a PyRef #837

thequux opened this issue Mar 26, 2020 · 1 comment · Fixed by #999

Comments

@thequux
Copy link

thequux commented Mar 26, 2020

I would like to be able to write code like the following:

#[pyclass]
struct Proxy {
    parent: Py<Foo>,
}

#[pyclass]
struct Foo {}

#[pymethods]
impl Foo {
    #[getter]
    fn proxy(slf: PyRef<Self>) -> Proxy {
        Proxy {
            parent: slf.into(),
        }
    }
}

However, this currently fails with the following error:

error: Getter function can only have one argument of type pyo3::Python
  --> src/lib.rs:12:20
   |
12 |     fn proxy(slf: PyRef<Self>) -> Proxy {
   |                   ^^^^^^^^^^^

(For completeness, this should also apply to setters, as well as support all of the other wrapper types for Python objects)

@kngwyu
Copy link
Member

kngwyu commented Mar 26, 2020

Yeah, I really agree that it's bad.
But since everything around __dunder__ is designed before PyRef or PyCell, it's hard to integrate them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants