Closed
Description
Compiles:
use pyo3::prelude::*;
#[pyclass]
#[derive(Debug)]
pub struct Foo {
field: i32
}
#[pymethods]
impl Foo {
#[new]
pub fn new(field: i32) -> Self {
Self { field }
}
}
Doesn't compile with Invalid type as custom self
and cannot find attribute 'new' in this scope
errors:
#[cfg(feature = "with_pyo3")]
use pyo3::prelude::*;
#[cfg_attr(feature = "with_pyo3", pyclass)]
#[derive(Debug)]
pub struct Foo {
field: i32
}
#[cfg_attr(feature = "with_pyo3", pymethods)]
impl Foo {
// Change `#[cfg_attr(feature = "with_pyo3", new)]` for `#[new]` and `cargo build --feature with_py03` to see a successful compilation.
#[cfg_attr(feature = "with_pyo3", new)]
pub fn new(field: i32) -> Self {
Self { field }
}
}