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

Cannot modify nested struct field with #[pyo3(set)] #1603

Closed
fschutt opened this issue May 12, 2021 · 1 comment
Closed

Cannot modify nested struct field with #[pyo3(set)] #1603

fschutt opened this issue May 12, 2021 · 1 comment

Comments

@fschutt
Copy link

fschutt commented May 12, 2021

Environment

  • Your operating system and version: Windows 8. 64-bit
  • Your python version: Python 3.6.5
  • How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: Windows Installer, no
  • Your Rust version (rustc --version): stable rustc 1.52.1 (9bc8c42bb 2021-05-09)
  • Your PyO3 version: 1ae3d87
  • Have you tried using latest PyO3 main (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: Yes

Reproducing

git clone https://github.com/fschutt/pyo3-bug
cargo build --release
cd target/release
cp ./azul.dll ./azul.pyd
# put the test.py file in /target/release
python ./test.py # see README

Rust code:

extern crate pyo3;

use pyo3::prelude::*;
use pyo3::Python;

#[pyclass]
#[repr(C)]
struct Wrapper {
    #[pyo3(get, set)]
    child: Child,
}

impl Clone for Wrapper {
    fn clone(&self) -> Self {
        Self {
            child: self.child.clone(),
        }
    }
}

#[pymethods]
impl Wrapper {
    #[new]
    fn new() -> Self {
        Self {
            child: Child { flag: true }
        }
    }
}

#[pyclass]
struct Child {
    #[pyo3(get, set)]
    flag: bool,
}

#[pymethods]
impl Child {
    #[new]
    fn new() -> Self {
        Self {
            flag: true
        }
    }
}

impl Clone for Child {
    fn clone(&self) -> Self {
        Self {
            flag: self.flag,
        }
    }
}

#[pymodule]
fn azul(py: Python, m: &PyModule) -> PyResult<()> {
    m.add_class::<Wrapper>()?;
    m.add_class::<Child>()?;

    Ok(())
}

Python code:

from azul import *

wrapper = Wrapper()
child = Child()

print(child.flag)               # ok: prints True (default)
print(wrapper.child.flag)       # ok: prints True (default)

# set both to False
child.flag = False
wrapper.child.flag = False

print(child.flag)               # ok: prints False (changed)
print(wrapper.child.flag)       # error: still prints True (not changed)

bug.zip

@davidhewitt
Copy link
Member

Hi @fschutt thanks for the report.

This is unfortunately known behaviour at the moment, though I hope one day we can improve this. Please see the duplicate ticket #1358 (comment)

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

No branches or pull requests

2 participants