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

Implementing __setattr__ errors #609

Closed
danieldk opened this issue Sep 30, 2019 · 1 comment · Fixed by #645
Closed

Implementing __setattr__ errors #609

danieldk opened this issue Sep 30, 2019 · 1 comment · Fixed by #645

Comments

@danieldk
Copy link
Contributor

🐛 Bug Reports

When reporting a bug, please provide the following information. If this is not a bug report you can just discard this template.

🌍 Environment

  • Your operating system and version: NixOS 19.09
  • Your python version: 3.7
  • How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: nix-shell
  • Your rust version (rustc --version): rustc 1.38.0-nightly (311376d30 2019-07-18)
  • Are you using the latest pyo3 version? No

💥 Reproducing

#[pyclass(name=Test)]
pub struct PyTest {
    foo: usize,
}

#[pyproto]
impl PyObjectProtocol for PyTest {
    fn __setattr__(&mut self, name: String, value: String) -> PyResult<()> {
        Ok(())
    }
}

Fails with:

error[E0437]: type `Success` is not a member of trait `pyo3::class::basic::PyObjectSetAttrProtocol`
   --> src/sentence.rs:251:1
    |
251 | #[pyproto]
    | ^^^^^^^^^^ not a member of trait `pyo3::class::basic::PyObjectSetAttrProtocol`

error: aborting due to previous error

__getattr__ works fine on the other hand.

@sebpuetz
Copy link
Contributor

Should be fixed by #645, in the meantime it's possible to replace the code generated by the proc-macro with the correct impls:

use pyo3::{PyObjectProtocol, PyResult};
use pyo3::prelude::*;
use pyo3::class::basic::PyObjectSetAttrProtocol;

#[pyclass(name=Test)]
pub struct PyTest {
    foo: usize,
}

impl<'p> PyObjectProtocol<'p> for PyTest {
    fn __setattr__(
        &'p mut self,
        name: <PyTest as PyObjectSetAttrProtocol<'p>>::Name,
        value: <PyTest as PyObjectSetAttrProtocol<'p>>::Value,
    ) -> <PyTest as PyObjectSetAttrProtocol<'p>>::Result {
        Ok(())
    }
}
impl<'p> PyObjectSetAttrProtocol<'p> for PyTest {
    type Name = String;
    type Value = String;
    type Result = PyResult<()>;
}

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

Successfully merging a pull request may close this issue.

2 participants