MCPcopy Index your code
hub / github.com/RustPython/RustPython / gen_module_item

Method gen_module_item

crates/derive-impl/src/pymodule.rs:654–720  ·  view source on GitHub ↗
(&self, args: ModuleItemArgs<'_>)

Source from the content-addressed store, hash-verified

652
653impl ModuleItem for FunctionItem {
654 fn gen_module_item(&self, args: ModuleItemArgs<'_>) -> Result<()> {
655 let func = args
656 .item
657 .function_or_method()
658 .map_err(|_| self.new_syn_error(args.item.span(), "can only be on a function"))?;
659 let ident = &func.sig().ident;
660
661 let item_attr = args.attrs.remove(self.index());
662 let item_meta = SimpleItemMeta::from_attr(ident.clone(), &item_attr)?;
663
664 let py_name = item_meta.simple_name()?;
665 let sig_doc = text_signature(func.sig(), &py_name);
666
667 let module = args.module_name();
668 // TODO: doc must exist at least one of code or CPython
669 let doc = args.attrs.doc().or_else(|| {
670 DB.get(&format!("{module}.{py_name}"))
671 .copied()
672 .map(str::to_owned)
673 });
674 let doc = if let Some(doc) = doc {
675 format_doc(&sig_doc, &doc)
676 } else {
677 sig_doc
678 };
679
680 let py_names = {
681 if self.py_attrs.is_empty() {
682 vec![py_name]
683 } else {
684 let mut py_names = HashSet::new();
685 py_names.insert(py_name);
686 for attr_index in self.py_attrs.iter().rev() {
687 let mut loop_unit = || {
688 let attr_attr = args.attrs.remove(*attr_index);
689 let item_meta = SimpleItemMeta::from_attr(ident.clone(), &attr_attr)?;
690
691 let py_name = item_meta.simple_name()?;
692 let inserted = py_names.insert(py_name.clone());
693 if !inserted {
694 return Err(self.new_syn_error(
695 ident.span(),
696 &format!(
697 "`{py_name}` is duplicated name for multiple py* attribute"
698 ),
699 ));
700 }
701 Ok(())
702 };
703 let r = loop_unit();
704 args.context.errors.ok_or_push(r);
705 }
706 let py_names: Vec<_> = py_names.into_iter().collect();
707 py_names
708 }
709 };
710 let call_flags = infer_native_call_flags(func.sig(), 0);
711

Callers 1

impl_pymoduleFunction · 0.80

Calls 15

text_signatureFunction · 0.85
format_docFunction · 0.85
newFunction · 0.85
infer_native_call_flagsFunction · 0.85
pyclass_ident_and_attrsFunction · 0.85
iter_use_identsFunction · 0.85
new_syn_errorMethod · 0.80
spanMethod · 0.80
simple_nameMethod · 0.80
module_nameMethod · 0.80
docMethod · 0.80
ok_or_pushMethod · 0.80

Tested by

no test coverage detected