Check if `expr` is a final attribute. This needs to be done differently for class and module attributes to correctly determine fully qualified name. Return a tuple that consists of the qualified name, the corresponding Var node, and a flag indicating whether the fina
(self, expr: MemberExpr)
| 1183 | return typ.is_named_tuple or typ.is_newtype or typ.typeddict_type is not None |
| 1184 | |
| 1185 | def get_final_ref(self, expr: MemberExpr) -> tuple[str, Var, bool] | None: |
| 1186 | """Check if `expr` is a final attribute. |
| 1187 | |
| 1188 | This needs to be done differently for class and module attributes to |
| 1189 | correctly determine fully qualified name. Return a tuple that consists of |
| 1190 | the qualified name, the corresponding Var node, and a flag indicating whether |
| 1191 | the final name was defined in a compiled module. Return None if `expr` does not |
| 1192 | refer to a final attribute. |
| 1193 | """ |
| 1194 | final_var = None |
| 1195 | if isinstance(expr.expr, RefExpr) and isinstance(expr.expr.node, TypeInfo): |
| 1196 | # a class attribute |
| 1197 | sym = expr.expr.node.get(expr.name) |
| 1198 | if sym and isinstance(sym.node, Var): |
| 1199 | # Enum attribute are treated as final since they are added to the global cache |
| 1200 | expr_fullname = expr.expr.node.bases[0].type.fullname |
| 1201 | is_final = sym.node.is_final or expr_fullname == "enum.Enum" |
| 1202 | if is_final: |
| 1203 | final_var = sym.node |
| 1204 | fullname = f"{sym.node.info.fullname}.{final_var.name}" |
| 1205 | native = self.is_native_module(expr.expr.node.module_name) |
| 1206 | elif self.is_module_member_expr(expr): |
| 1207 | # a module attribute |
| 1208 | if isinstance(expr.node, Var) and expr.node.is_final: |
| 1209 | final_var = expr.node |
| 1210 | fullname = expr.node.fullname |
| 1211 | native = self.is_native_ref_expr(expr) |
| 1212 | if final_var is not None: |
| 1213 | return fullname, final_var, native |
| 1214 | return None |
| 1215 | |
| 1216 | def emit_load_final( |
| 1217 | self, final_var: Var, fullname: str, name: str, native: bool, typ: Type, line: int |
no test coverage detected