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

Function populate_singletons

crates/vm/src/stdlib/_ast/pyast.rs:1789–1813  ·  view source on GitHub ↗
(vm: &VirtualMachine, module: &Py<PyModule>)

Source from the content-addressed store, hash-verified

1787}
1788
1789fn populate_singletons(vm: &VirtualMachine, module: &Py<PyModule>) {
1790 let instance_attr = vm.ctx.intern_str("_instance");
1791 const SINGLETON_TYPES: &[&str] = &[
1792 // expr_context
1793 "Load", "Store", "Del", // boolop
1794 "And", "Or", // operator
1795 "Add", "Sub", "Mult", "MatMult", "Div", "Mod", "Pow", "LShift", "RShift", "BitOr",
1796 "BitXor", "BitAnd", "FloorDiv", // unaryop
1797 "Invert", "Not", "UAdd", "USub", // cmpop
1798 "Eq", "NotEq", "Lt", "LtE", "Gt", "GtE", "Is", "IsNot", "In", "NotIn",
1799 ];
1800
1801 for &class_name in SINGLETON_TYPES {
1802 let class = module
1803 .get_attr(class_name, vm)
1804 .unwrap_or_else(|_| panic!("AST class '{class_name}' not found in module"));
1805 let Some(type_obj) = class.downcast_ref::<PyType>() else {
1806 continue;
1807 };
1808 let instance = vm
1809 .ctx
1810 .new_base_object(type_obj.to_owned(), Some(vm.ctx.new_dict()));
1811 type_obj.set_attr(instance_attr, instance);
1812 }
1813}
1814
1815fn force_ast_module_name(vm: &VirtualMachine, module: &Py<PyModule>) {
1816 let ast_name = vm.ctx.new_str("ast");

Callers 1

extend_module_nodesFunction · 0.85

Calls 7

intern_strMethod · 0.80
new_base_objectMethod · 0.80
new_dictMethod · 0.80
SomeClass · 0.50
get_attrMethod · 0.45
to_ownedMethod · 0.45
set_attrMethod · 0.45

Tested by

no test coverage detected