Replace cross-reference with an actual referred node.
(self, value: SymbolTableNode)
| 133 | value.stored_info = self.current_info |
| 134 | |
| 135 | def resolve_cross_ref(self, value: SymbolTableNode) -> None: |
| 136 | """Replace cross-reference with an actual referred node.""" |
| 137 | assert value.cross_ref is not None |
| 138 | cross_ref = value.cross_ref |
| 139 | value.cross_ref = None |
| 140 | value.unfixed = False |
| 141 | stnode = lookup_fully_qualified( |
| 142 | cross_ref, self.modules, raise_on_missing=not self.allow_missing |
| 143 | ) |
| 144 | if stnode is not None: |
| 145 | if stnode is value: |
| 146 | # The node seems to refer to itself, which can mean that |
| 147 | # the target is a deleted submodule of the current module, |
| 148 | # and thus lookup falls back to the symbol table of the parent |
| 149 | # package. Here's how this may happen: |
| 150 | # |
| 151 | # pkg/__init__.py: |
| 152 | # from pkg import sub |
| 153 | # |
| 154 | # Now if pkg.sub is deleted, the pkg.sub symbol table entry |
| 155 | # appears to refer to itself. Replace the entry with a |
| 156 | # placeholder to avoid a crash. We can't delete the entry, |
| 157 | # as it would stop dependency propagation. |
| 158 | short_name = cross_ref.rsplit(".", maxsplit=1)[-1] |
| 159 | value._node = Var(short_name + "@deleted") |
| 160 | else: |
| 161 | assert stnode.node is not None, cross_ref |
| 162 | value._node = stnode.node |
| 163 | elif not self.allow_missing: |
| 164 | assert False, f"Could not find cross-ref {cross_ref}" |
| 165 | else: |
| 166 | # We have a missing crossref in allow missing mode, need to put something |
| 167 | value._node = missing_info(self.modules) |
| 168 | |
| 169 | def visit_func_def(self, func: FuncDef) -> None: |
| 170 | if func.type is not None: |
no test coverage detected