Create a new-to-old object identity map by comparing two symbol table revisions. Both symbol tables must refer to revisions of the same module id. The symbol tables are compared recursively (recursing into nested class symbol tables), but only within the given module prefix. Don't recur
(
old: SymbolTable, new: SymbolTable, prefix: str
)
| 146 | |
| 147 | |
| 148 | def replacement_map_from_symbol_table( |
| 149 | old: SymbolTable, new: SymbolTable, prefix: str |
| 150 | ) -> dict[SymbolNode, SymbolNode]: |
| 151 | """Create a new-to-old object identity map by comparing two symbol table revisions. |
| 152 | |
| 153 | Both symbol tables must refer to revisions of the same module id. The symbol tables |
| 154 | are compared recursively (recursing into nested class symbol tables), but only within |
| 155 | the given module prefix. Don't recurse into other modules accessible through the symbol |
| 156 | table. |
| 157 | """ |
| 158 | replacements: dict[SymbolNode, SymbolNode] = {} |
| 159 | for name, node in old.items(): |
| 160 | if name in new and ( |
| 161 | node.kind == MDEF or node.node and get_prefix(node.node.fullname) == prefix |
| 162 | ): |
| 163 | new_node = new[name] |
| 164 | if ( |
| 165 | type(new_node.node) == type(node.node) |
| 166 | and new_node.node |
| 167 | and node.node |
| 168 | and new_node.node.fullname == node.node.fullname |
| 169 | and new_node.kind == node.kind |
| 170 | ): |
| 171 | replacements[new_node.node] = node.node |
| 172 | if isinstance(node.node, TypeInfo) and isinstance(new_node.node, TypeInfo): |
| 173 | type_repl = replacement_map_from_symbol_table( |
| 174 | node.node.names, new_node.node.names, prefix |
| 175 | ) |
| 176 | replacements.update(type_repl) |
| 177 | if node.node.special_alias and new_node.node.special_alias: |
| 178 | replacements[new_node.node.special_alias] = node.node.special_alias |
| 179 | return replacements |
| 180 | |
| 181 | |
| 182 | def replace_nodes_in_ast( |
no test coverage detected
searching dependent graphs…