Skip to content

Commit c0de1ea

Browse files
committed
util path to string
1 parent eb1f78d commit c0de1ea

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

derive/src/pymodule.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,14 @@ where
184184
let mut pyattrs = Vec::new();
185185
for (i, attr) in iter {
186186
// take py items but no cfgs
187-
let attr_name = if let Some(ident) = attr.get_ident() {
188-
ident.to_string()
189-
} else {
190-
continue;
191-
};
187+
let attr_name = attr.path.to_string();
192188
if attr_name == "cfg" {
193189
return Err(syn::Error::new_spanned(
194190
attr,
195191
"#[py*] items must be placed under `cfgs`",
196192
));
197193
}
194+
let attr_name = attr_name.replace("::", "");
198195

199196
let attr_name = match AttrName::from_str(attr_name.as_str()) {
200197
Ok(name) => name,

derive/src/util.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ pub(crate) const ALL_ALLOWED_NAMES: &[&str] = &[
2525
"extend_class",
2626
];
2727

28+
pub fn path_to_string(path: &syn::Path) -> String {
29+
let x = format!("{}", quote! {#path});
30+
x.replace(' ', "")
31+
}
32+
2833
#[derive(Default)]
2934
pub(crate) struct ItemNursery(IndexMap<(String, Vec<Attribute>), TokenStream>);
3035

@@ -346,6 +351,7 @@ pub(crate) fn path_eq(path: &Path, s: &str) -> bool {
346351
}
347352

348353
pub(crate) trait AttributeExt: SynAttributeExt {
354+
fn path_string(&self) -> String;
349355
fn promoted_nested(&self) -> Result<PunctuatedNestedMeta>;
350356
fn ident_and_promoted_nested(&self) -> Result<(&Ident, PunctuatedNestedMeta)>;
351357
fn try_remove_name(&mut self, name: &str) -> Result<Option<syn::NestedMeta>>;
@@ -355,9 +361,12 @@ pub(crate) trait AttributeExt: SynAttributeExt {
355361
}
356362

357363
impl AttributeExt for Attribute {
364+
fn path_string(&self) -> String {
365+
path_to_string(&self.path)
366+
}
358367
fn promoted_nested(&self) -> Result<PunctuatedNestedMeta> {
359368
let list = self.promoted_list().map_err(|mut e| {
360-
let name = self.get_ident().unwrap().to_string();
369+
let name = self.path_string();
361370
e.combine(syn::Error::new_spanned(
362371
self,
363372
format!(

0 commit comments

Comments
 (0)