-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow
#[classattr]
on associated constants
- Loading branch information
Showing
6 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use crate::pyfunction::parse_name_attribute; | ||
use syn::ext::IdentExt; | ||
|
||
#[derive(Clone, PartialEq, Debug)] | ||
pub struct ConstSpec { | ||
pub is_class_attr: bool, | ||
pub python_name: syn::Ident, | ||
} | ||
|
||
impl ConstSpec { | ||
// For now, the only valid attribute is `#[classattr]`. | ||
pub fn parse(name: &syn::Ident, attrs: &mut Vec<syn::Attribute>) -> syn::Result<ConstSpec> { | ||
let mut new_attrs = Vec::new(); | ||
let mut is_class_attr = false; | ||
|
||
for attr in attrs.iter() { | ||
if let syn::Meta::Path(name) = attr.parse_meta()? { | ||
if name.is_ident("classattr") { | ||
is_class_attr = true; | ||
continue; | ||
} | ||
} | ||
new_attrs.push(attr.clone()); | ||
} | ||
|
||
attrs.clear(); | ||
attrs.extend(new_attrs); | ||
|
||
Ok(ConstSpec { | ||
is_class_attr, | ||
python_name: parse_name_attribute(attrs)?.unwrap_or_else(|| name.unraw()), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
mod defs; | ||
mod func; | ||
mod konst; | ||
mod method; | ||
mod module; | ||
mod pyclass; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters