(vm: &VirtualMachine, module: &Py<PyModule>)
| 1787 | } |
| 1788 | |
| 1789 | fn 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 | |
| 1815 | fn force_ast_module_name(vm: &VirtualMachine, module: &Py<PyModule>) { |
| 1816 | let ast_name = vm.ctx.new_str("ast"); |
no test coverage detected