Fix bug which made code generation dependend on argument ordering

This commit is contained in:
konstin 2018-07-06 12:56:40 +02:00
parent 1201587353
commit 562d417517
3 changed files with 11 additions and 10 deletions

View File

@ -5,14 +5,12 @@
extern crate pyo3; extern crate pyo3;
extern crate rayon; extern crate rayon;
use pyo3::prelude::*;
use pyo3::py::{class, methods, modinit};
use rayon::prelude::*;
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
use pyo3::prelude::*;
use rayon::prelude::*;
use pyo3::py::{class, methods, modinit};
#[class(dict)] #[class(dict)]
struct WordCounter { struct WordCounter {
path: String, path: String,

View File

@ -16,8 +16,11 @@ pub fn build_py_class(class: &mut syn::ItemStruct, attr: &Vec<syn::Expr>) -> Tok
if let syn::Fields::Named(ref mut fields) = class.fields { if let syn::Fields::Named(ref mut fields) = class.fields {
for field in fields.named.iter_mut() { for field in fields.named.iter_mut() {
if is_python_token(field) { if is_python_token(field) {
if token.is_none() {
token = field.ident.clone(); token = field.ident.clone();
break; } else {
panic!("You can only have one PyToken per class");
}
} else { } else {
let field_descs = parse_descriptors(field); let field_descs = parse_descriptors(field);
if !field_descs.is_empty() { if !field_descs.is_empty() {
@ -48,8 +51,8 @@ fn parse_descriptors(item: &mut syn::Field) -> Vec<FnType> {
"set" => { "set" => {
descs.push(FnType::Setter(None)); descs.push(FnType::Setter(None));
} }
_ => { x => {
panic!("Only getter and setter supported"); panic!(r#"Only "get" and "set" supported are, not "{}""#, x);
} }
} }
} }

View File

@ -52,11 +52,11 @@ fn class_with_properties() {
#[class] #[class]
struct GetterSetter { struct GetterSetter {
token: PyToken,
#[prop(get, set)] #[prop(get, set)]
num: i32, num: i32,
#[prop(get, set)] #[prop(get, set)]
text: String, text: String,
token: PyToken,
} }
#[methods] #[methods]