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

expected struct pyo3::PyClassInitializer, found struct pyo3::pyclass_init::PyNativeTypeInitializer #958

Closed
rth opened this issue Jun 5, 2020 · 2 comments

Comments

@rth
Copy link

rth commented Jun 5, 2020

While updating vtext crate from Pyo3 0.8 to 0.10 (and following the migration guide) I am getting the following error,

error[E0271]: type mismatch resolving `<tokenize::BaseTokenizer as pyo3::PyTypeInfo>::Initializer == pyo3::pyclass_init::PyNativeTypeInitializer<tokenize::BaseTokenizer>`
  --> src/tokenize.rs:40:1
   |
40 | #[pymethods]
   | ^^^^^^^^^^^^ expected struct `pyo3::PyClassInitializer`, found struct `pyo3::pyclass_init::PyNativeTypeInitializer`
   |
   = note: expected struct `pyo3::PyClassInitializer<tokenize::BaseTokenizer>`
              found struct `pyo3::pyclass_init::PyNativeTypeInitializer<tokenize::BaseTokenizer>`
   = note: required because of the requirements on the impl of `std::convert::From<tokenize::UnicodeSegmentTokenizer>` for `pyo3::PyClassInitializer<tokenize::UnicodeSegmentTokenizer>`
   = note: required because of the requirements on the impl of `std::convert::Into<pyo3::PyClassInitializer<tokenize::UnicodeSegmentTokenizer>>` for `tokenize::UnicodeSegmentTokenizer`
   = note: required because of the requirements on the impl of `pyo3::derive_utils::IntoPyNewResult<tokenize::UnicodeSegmentTokenizer, tokenize::UnicodeSegmentTokenizer>` for `tokenize::UnicodeSegmentTokenizer`
   = note: required by `pyo3::derive_utils::IntoPyNewResult::into_pynew_result`
   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

🌍 Environment

  • Your operating system and version: Linux 5.0.0-38-generic Ubuntu 19.04
  • Your python version: 3.7.4
  • How did you install python? Conda with a conda virtualenv
  • Your Rust version (rustc --version): rustc 1.45.0-nightly (5fd2f06e9 2020-05-31)
  • Your PyO3 version: v0.10.1
  • Have you tried using latest PyO3 master (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: I get the same error on master

💥 Reproducing

Sorry not a minimal example, but this can be reproduced by running pip install -e . -v in rth/vtext#69 where the problematic class in question is for instance https://github.com/rth/vtext/blob/2337529bed5caf42221df01df686ed0c69ed3f58/python/src/tokenize.rs#L12-L54

I saw nothing related in the issue tracker, if anyone has pointer of for where to look that would be very much appreciated. It does seem to be related to the addition of the new #[pyclass] system in #683

Edit: could that issue be that the rust struct and the PyO3 struct that wraps it has the same name? Certainly not ideal, but it used to work before..

@kngwyu
Copy link
Member

kngwyu commented Jun 5, 2020

Now extended classes should return a tuple: (BaseClass{}, Class{}).
See https://pyo3.rs/v0.10.1/class.html#inheritance for more.

@rth
Copy link
Author

rth commented Jun 5, 2020

Ahh, makes sense. Thank you @kngwyu !

@rth rth closed this as completed Jun 5, 2020
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