pyattr allows use group

This commit is contained in:
Jeong YunWon committed 2020-09-19 07:47:57 +09:00
1 parent 58e6a4702d
commit 52e19c2331
2 files changed
+40 -10

No files matched your search

+36 -1
View File
@@ -366,8 +366,43 @@ impl ModuleItem for AttributeItem {
let ident = match &*path.tree {
UseTree::Name(name) => &name.ident,
UseTree::Rename(rename) => &rename.rename,
UseTree::Group(syn::UseGroup { items, .. }) => {
for item in items {
let ident = match item {
UseTree::Name(name) => &name.ident,
UseTree::Rename(rename) => &rename.rename,
other => {
return Err(self.new_syn_error(
other.span(),
"can only contains a simple use or a group of simple uses",
));
}
};
let item_meta = SimpleItemMeta::from_attr(ident.clone(), &attr)?;
if item_meta.optional_name().is_some() {
// this check actually doesn't need to be placed in loop
return Err(self.new_syn_error(
ident.span(),
"`name` attribute is not allowed for multiple use items",
));
}
let py_name = ident.to_string();
let tokens = quote! {
vm.__module_set_attr(&module, #py_name, vm.new_pyobj(#ident)).unwrap();
};
args.context.module_extend_items.add_item(
py_name,
cfgs.clone(),
tokens,
)?;
}
return Ok(());
}
other => {
return Err(self.new_syn_error(other.span(), "can only be a simple use"));
return Err(self.new_syn_error(
other.span(),
"can only contains a simple use or a group of simple uses",
));
}
};
+4 -9
View File
@@ -23,15 +23,10 @@ mod decl {
use std::io::Write;
#[pyattr]
use libz::Z_BEST_COMPRESSION;
#[pyattr]
use libz::Z_BEST_SPEED;
#[pyattr]
use libz::Z_DEFAULT_COMPRESSION;
#[pyattr]
use libz::Z_DEFLATED as DEFLATED;
#[pyattr]
use libz::Z_NO_COMPRESSION;
use libz::{
Z_BEST_COMPRESSION, Z_BEST_SPEED, Z_DEFAULT_COMPRESSION, Z_DEFLATED as DEFLATED,
Z_NO_COMPRESSION,
};
// copied from zlibmodule.c (commit 530f506ac91338)
#[pyattr]