You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The doc describes how to subclass from "classes" created in rust, however either the feature isn't there yet or the docs are missing on how to inherit from an imported subclass. It would be great if either the doc were extended or subclassing imported classes made possible.
🌍 Environment
Your operating system and version: openSUSE Leap 15.2
Your python version: 3.6.12
How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?:
sudo zypper in -y python3-devel
Your Rust version (rustc --version): rustc 1.45.0 (5c1f21c3b 2020-07-13)
Your PyO3 version: 0.13.1
Have you tried using latest PyO3 master (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: yes
💥 Reproducing
My rudimentary rust knowledge won't let me get around the errors generated in this example
Cargo.toml
[package]
name = "rust-in-django"version = "0.1.0"authors = ["LoveIsGrief <>"]
edition = "2018"
[lib]
name = "rust_in_django"crate-type = ["cdylib"]
[dependencies.pyo3]
version = "0.13.1"features = [
"auto-initialize",
"extension-module",
]
src/lib.rs
use pyo3::prelude::*;use pyo3::types::PyType;#[pyclass]structSomething{}/// A Python module implemented in Rust.#[pymodule]fnrust_in_django(py:Python,m:&PyModule) -> PyResult<()>{let result = py.import("django.db.models").unwrap();let model = result.get("Model").unwrap();#[pymethods]implSomething{#[new]fnnew() -> PyClassInitializer<Self>{PyClassInitializer::from(model::new()).add_subclass(Something{})}#[classmethod]fnsay(cls:&PyType){println!("printed something");}}
m.add_class::<Something>()?;Ok(())}
error[E0433]: failed to resolve: use of undeclared type or module `model`
--> src/lib.rs:18:38
|
18 | PyClassInitializer::from(model::new())
| ^^^^^ use of undeclared type or module `model`
error[E0433]: failed to resolve: use of undeclared type or module `model`
--> src/lib.rs:18:38
|
18 | PyClassInitializer::from(model::new())
| ^^^^^ use of undeclared type or module `model`
error[E0271]: type mismatch resolving `<pyo3::types::any::PyAny as pyo3::type_object::PyTypeInfo>::Initializer == pyo3::pyclass_init::PyClassInitializer<pyo3::types::any::PyAny>`
--> src/lib.rs:19:18
|
19 | .add_subclass(Something{})
| ^^^^^^^^^^^^ expected struct `pyo3::pyclass_init::PyNativeTypeInitializer`, found struct `pyo3::pyclass_init::PyClassInitializer`
|
= note: expected struct `pyo3::pyclass_init::PyNativeTypeInitializer<pyo3::types::any::PyAny>`
found struct `pyo3::pyclass_init::PyClassInitializer<pyo3::types::any::PyAny>`
The text was updated successfully, but these errors were encountered:
🌟 Feature request
The doc describes how to subclass from "classes" created in rust, however either the feature isn't there yet or the docs are missing on how to inherit from an imported subclass. It would be great if either the doc were extended or subclassing imported classes made possible.
🌍 Environment
sudo zypper in -y python3-devel
rustc --version
): rustc 1.45.0 (5c1f21c3b 2020-07-13)version = "0.x.y"
withgit = "https://github.com/PyO3/pyo3")?
: yes💥 Reproducing
My rudimentary rust knowledge won't let me get around the errors generated in this example
Cargo.toml
src/lib.rs
The text was updated successfully, but these errors were encountered: