I am writing a python library with a Rust backend using pyo3 and I don't understand why there isn't an error thrown when you call the wrong constructor, I think what I'm saying will make more sense when I show the code.
// vector.rs
use pyo3::prelude::*;
#[pyclass]
pub struct Vector {
#[pyo3(get, set)]
x: f64,
#[pyo3(get, set)]
y: f64,
#[pyo3(get, set)]
z: f64
}
#[pymethods]
impl Vector {
#[new]
fn new() -> Self {
Vector {
x: 0.0,
y: 0.0,
z: 0.0
}
}
}
// lib.rs
mod core;
use pyo3::prelude::*;
use crate::core::vector::Vector;
#[pymodule]
fn imagine(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<Vector>()?;
Ok(())
}
It compiles fine but when I use the wrong constructor it doesn't raise any errors.
>>> from imagine import *
>>> a = Vector("yo")
>>> a
<Vector object at 0x10eb5e650>