Skip to content

Commit f362a40

Browse files
committed
poc py::function
1 parent c0de1ea commit f362a40

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

derive/src/pymodule.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,11 @@ where
169169
while let Some((_, attr)) = iter.peek() {
170170
// take all cfgs but no py items
171171
let attr = *attr;
172-
if let Some(ident) = attr.get_ident() {
173-
let attr_name = ident.to_string();
174-
if attr_name == "cfg" {
175-
cfgs.push(attr.clone());
176-
} else if ALL_ALLOWED_NAMES.contains(&attr_name.as_str()) {
177-
break;
178-
}
172+
let attr_path = attr.path_string();
173+
if attr_path == "cfg" {
174+
cfgs.push(attr.clone());
175+
} else if attr_path.starts_with("py") {
176+
break;
179177
}
180178
iter.next();
181179
}
@@ -184,7 +182,7 @@ where
184182
let mut pyattrs = Vec::new();
185183
for (i, attr) in iter {
186184
// take py items but no cfgs
187-
let attr_name = attr.path.to_string();
185+
let attr_name = attr.path_string();
188186
if attr_name == "cfg" {
189187
return Err(syn::Error::new_spanned(
190188
attr,

derive/src/util.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,15 @@ impl AttributeExt for Attribute {
380380
Ok(list.nested)
381381
}
382382
fn ident_and_promoted_nested(&self) -> Result<(&Ident, PunctuatedNestedMeta)> {
383-
Ok((self.get_ident().unwrap(), self.promoted_nested()?))
383+
let ident = self.get_ident().unwrap_or_else(|| {
384+
&self
385+
.path
386+
.segments
387+
.last()
388+
.expect("py:: paths always have segment")
389+
.ident
390+
});
391+
Ok((ident, self.promoted_nested()?))
384392
}
385393

386394
fn try_remove_name(&mut self, item_name: &str) -> Result<Option<syn::NestedMeta>> {

vm/src/stdlib/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ mod builtins {
3737
};
3838
use num_traits::{Signed, ToPrimitive, Zero};
3939

40-
#[pyfunction]
40+
#[py::function]
4141
fn abs(x: PyObjectRef, vm: &VirtualMachine) -> PyResult {
4242
vm._abs(&x)
4343
}

0 commit comments

Comments
 (0)