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

added init() in __new__ #61

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions rust/altrios-core/altrios-proc-macros/src/altrios_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ pub(crate) fn altrios_api(attr: TokenStream, item: TokenStream) -> TokenStream {
quote! {
#[new]
/// Rust-defined `__new__` magic method for Python used exposed via PyO3.
fn __new__(v: Vec<#contained_dtype>) -> Self {
Self(v)
fn __new__(v: Vec<#contained_dtype>) -> PyResult<Self> {
let mut v = v.clone();
v.init()?;
Ok(Self(v))
}
/// Rust-defined `__repr__` magic method for Python used exposed via PyO3.
fn __repr__(&self) -> String {
Expand All @@ -122,7 +124,7 @@ pub(crate) fn altrios_api(attr: TokenStream, item: TokenStream) -> TokenStream {
then set entire list.",
))
}
/// PyO3-exposed method to convert vec-containing struct to Python list.
/// PyO3-exposed method to convert vec-containing struct to Python list.
fn tolist(&self) -> anyhow::Result<Vec<#contained_dtype>> {
Ok(self.0.clone())
}
Expand Down
Loading