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

Function merge_asts

mypy/server/astmerge.py:117–145  ·  view source on GitHub ↗

Merge a new version of a module AST to a previous version. The main idea is to preserve the identities of externally visible nodes in the old AST (that have a corresponding node in the new AST). All old node state (outside identity) will come from the new AST. When this returns, 'o

(
    old: MypyFile, old_symbols: SymbolTable, new: MypyFile, new_symbols: SymbolTable
)

Source from the content-addressed store, hash-verified

115
116
117def merge_asts(
118 old: MypyFile, old_symbols: SymbolTable, new: MypyFile, new_symbols: SymbolTable
119) -> None:
120 """Merge a new version of a module AST to a previous version.
121
122 The main idea is to preserve the identities of externally visible
123 nodes in the old AST (that have a corresponding node in the new AST).
124 All old node state (outside identity) will come from the new AST.
125
126 When this returns, 'old' will refer to the merged AST, but 'new_symbols'
127 will be the new symbol table. 'new' and 'old_symbols' will no longer be
128 valid.
129 """
130 assert new.fullname == old.fullname
131 # Find the mapping from new to old node identities for all nodes
132 # whose identities should be preserved.
133 replacement_map = replacement_map_from_symbol_table(
134 old_symbols, new_symbols, prefix=old.fullname
135 )
136 # Also replace references to the new MypyFile node.
137 replacement_map[new] = old
138 # Perform replacements to everywhere within the new AST (not including symbol
139 # tables).
140 node = replace_nodes_in_ast(new, replacement_map)
141 assert node is old
142 # Also replace AST node references in the *new* symbol table (we'll
143 # continue to use the new symbol table since it has all the new definitions
144 # that have no correspondence in the old AST).
145 replace_nodes_in_symbol_table(new_symbols, replacement_map)
146
147
148def replacement_map_from_symbol_table(

Callers 2

reprocess_nodesFunction · 0.90

Calls 3

replace_nodes_in_astFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…