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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheritance example does not compile #381

Closed
Alexander-N opened this issue Mar 2, 2019 · 2 comments
Closed

Inheritance example does not compile #381

Alexander-N opened this issue Mar 2, 2019 · 2 comments
Labels

Comments

@Alexander-N
Copy link
Member

馃悰 Bug Reports

馃實 Environment

  • Your operating system and version: Ubuntu 18.10
  • Your python version: 3.6.7
  • How did you install python (e.g. apt or pyenv)? apt
  • Did you use a virtualenv?: no
  • Your rust version (rustc --version): rustc 1.34.0-nightly (aadbc459b 2019-02-23)
  • Are you using the latest pyo3 version? Have you tried using latest master (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")? yes

馃挜 Reproducing

The following code from https://pyo3.rs/master/class.html#inheritance

#![allow(unused_variables)]
fn main() {
   use pyo3::prelude::*;
   use pyo3::PyRawObject;
   #[pyclass]
   struct BaseClass {
      val1: usize,
   }

   #[pymethods]
   impl BaseClass {
      #[new]
      fn new(obj: &PyRawObject) {
         obj.init(BaseClass { val1: 10 });
      }

      pub fn method(&self) -> PyResult<()> {
         Ok(())
      }
   }

   #[pyclass(extends=BaseClass)]
   struct SubClass {
      val2: usize,
   }

   #[pymethods]
   impl SubClass {
      #[new]
      fn new(obj: &PyRawObject) {
         obj.init(SubClass { val2: 10 });
         BaseClass::new(obj);
      }

      fn method2(&self) -> PyResult<()> {
         self.get_base().method()
      }
   }
}

gives me

error[E0599]: no method named `get_base` found for type `&main::SubClass` in the current scope
  --> src/main.rs:93:15
   |
93 |          self.get_base().method()
   |               ^^^^^^^^
   |
   = note: the method `get_base` exists but the following trait bounds were not satisfied:
           `&main::SubClass : pyo3::objectprotocol::ObjectProtocol`
           `main::SubClass : pyo3::objectprotocol::ObjectProtocol`
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `get_base`, perhaps you need to implement it:
           candidate #1: `pyo3::objectprotocol::ObjectProtocol`
@kngwyu
Copy link
Member

kngwyu commented Mar 4, 2019

Looks current implementation is only for T: PyObjectNativeType + AsPyPointer so we can't actually use it 馃

@kngwyu kngwyu added this to the 0.6.0 milestone Mar 4, 2019
@konstin konstin added the bug label Mar 4, 2019
Alexander-N added a commit to Alexander-N/pyo3 that referenced this issue Mar 4, 2019
Does not work currently, see PyO3#381
Alexander-N added a commit to Alexander-N/pyo3 that referenced this issue Mar 4, 2019
Also ignore inheritance example in class.md since it does not work
currently, see PyO3#381
Alexander-N added a commit to Alexander-N/pyo3 that referenced this issue Mar 5, 2019
Also ignore inheritance example in class.md since it does not work
currently, see PyO3#381
Alexander-N added a commit to Alexander-N/pyo3 that referenced this issue Mar 9, 2019
Also ignore inheritance example in class.md since it does not work
currently, see PyO3#381
Alexander-N added a commit to Alexander-N/pyo3 that referenced this issue Mar 9, 2019
Test could only be activated for Python 3.5 and some tests had to be
ignored, see PyO3#381 and PyO3#387.
@konstin konstin removed this from the 0.6.0 milestone Mar 17, 2019
@konstin konstin mentioned this issue Mar 18, 2019
1 task
@Alexander-N
Copy link
Member Author

get_base was removed in #770.

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

No branches or pull requests

3 participants