(
self,
imported_id: str,
existing_symbol: SymbolTableNode,
module_symbol: SymbolTableNode,
import_node: ImportBase,
)
| 3178 | ) |
| 3179 | |
| 3180 | def process_import_over_existing_name( |
| 3181 | self, |
| 3182 | imported_id: str, |
| 3183 | existing_symbol: SymbolTableNode, |
| 3184 | module_symbol: SymbolTableNode, |
| 3185 | import_node: ImportBase, |
| 3186 | ) -> bool: |
| 3187 | if existing_symbol.node is module_symbol.node: |
| 3188 | # We added this symbol on previous iteration. |
| 3189 | return False |
| 3190 | if existing_symbol.kind in (LDEF, GDEF, MDEF) and isinstance( |
| 3191 | existing_symbol.node, (Var, FuncDef, TypeInfo, Decorator, TypeAlias) |
| 3192 | ): |
| 3193 | # This is a valid import over an existing definition in the file. Construct a dummy |
| 3194 | # assignment that we'll use to type check the import. |
| 3195 | lvalue = NameExpr(imported_id) |
| 3196 | lvalue.kind = existing_symbol.kind |
| 3197 | lvalue.node = existing_symbol.node |
| 3198 | rvalue = NameExpr(imported_id) |
| 3199 | rvalue.kind = module_symbol.kind |
| 3200 | rvalue.node = module_symbol.node |
| 3201 | if isinstance(rvalue.node, TypeAlias): |
| 3202 | # Suppress bogus errors from the dummy assignment if rvalue is an alias. |
| 3203 | # Otherwise mypy may complain that alias is invalid in runtime context. |
| 3204 | rvalue.is_alias_rvalue = True |
| 3205 | assignment = AssignmentStmt([lvalue], rvalue) |
| 3206 | for node in assignment, lvalue, rvalue: |
| 3207 | node.set_line(import_node) |
| 3208 | import_node.assignments.append(assignment) |
| 3209 | return True |
| 3210 | return False |
| 3211 | |
| 3212 | def correct_relative_import(self, node: ImportFrom | ImportAll) -> str: |
| 3213 | import_id, ok = correct_relative_import( |
no test coverage detected