Loads a Python-level global. This takes a NameExpr and uses its name as a key to retrieve the corresponding PyObject * from the _globals dictionary in the C-generated code.
(self, expr: NameExpr)
| 1515 | return "." in expr.node.fullname and expr.node.fullname.split(".")[0] == "builtins" |
| 1516 | |
| 1517 | def load_global(self, expr: NameExpr) -> Value: |
| 1518 | """Loads a Python-level global. |
| 1519 | |
| 1520 | This takes a NameExpr and uses its name as a key to retrieve the corresponding PyObject * |
| 1521 | from the _globals dictionary in the C-generated code. |
| 1522 | """ |
| 1523 | # If the global is from 'builtins', turn it into a module attr load instead |
| 1524 | if self.is_builtin_ref_expr(expr): |
| 1525 | assert expr.node, "RefExpr not resolved" |
| 1526 | return self.load_module_attr_by_fullname(expr.node.fullname, expr.line) |
| 1527 | if ( |
| 1528 | self.is_native_module_ref_expr(expr) |
| 1529 | and isinstance(expr.node, TypeInfo) |
| 1530 | and not self.is_synthetic_type(expr.node) |
| 1531 | ): |
| 1532 | assert expr.fullname |
| 1533 | return self.load_native_type_object(expr.fullname) |
| 1534 | return self.load_global_str(expr.name, expr.line) |
| 1535 | |
| 1536 | def load_global_str(self, name: str, line: int) -> Value: |
| 1537 | _globals = self.load_globals_dict() |
no test coverage detected