MCPcopy Index your code
hub / github.com/python/mypy / replacement_map_from_symbol_table

Function replacement_map_from_symbol_table

mypy/server/astmerge.py:148–179  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

146
147
148def 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
182def replace_nodes_in_ast(

Callers 1

merge_astsFunction · 0.85

Calls 5

get_prefixFunction · 0.90
typeClass · 0.85
isinstanceFunction · 0.85
itemsMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…