module documentation

Strip/reset AST in-place to match state after semantic analyzer pre-analysis. Fine-grained incremental mode reruns semantic analysis main pass and type checking for *existing* AST nodes (targets) when changes are propagated using fine-grained dependencies. AST nodes attributes are sometimes changed during semantic analysis main pass, and running semantic analysis again on those nodes would produce incorrect results, since this pass isn't idempotent. This pass resets AST nodes to reflect the state after semantic pre-analysis, so that we can rerun semantic analysis. (The above is in contrast to behavior with modules that have source code changes, for which we re-parse the entire module and reconstruct a fresh AST. No stripping is required in this case. Both modes of operation should have the same outcome.) Notes: * This is currently pretty fragile, as we must carefully undo whatever changes can be made in semantic analysis main pass, including changes to symbol tables. * We reuse existing AST nodes because it makes it relatively straightforward to reprocess only a single target within a module efficiently. If there was a way to parse a single target within a file, in time proportional to the size of the target, we'd rather create fresh AST nodes than strip them. (This is possible only in Python 3.8+) * Currently we don't actually reset all changes, but only those known to affect non-idempotent semantic analysis behavior. TODO: It would be more principled and less fragile to reset everything changed in semantic analysis main pass and later. * Reprocessing may recreate AST nodes (such as Var nodes, and TypeInfo nodes created with assignment statements) that will get different identities from the original AST. Thus running an AST merge is necessary after stripping, even though some identities are preserved.

Class NodeStripVisitor No class docstring; 0/4 instance variable, 3/22 methods documented
Function strip_target Reset a fine-grained incremental target to state before semantic analysis.
Type Alias SavedAttributes Undocumented
def strip_target(node: (MypyFile|FuncDef)|OverloadedFuncDef, saved_attrs: SavedAttributes): (source)

Reset a fine-grained incremental target to state before semantic analysis. All TypeInfos are killed. Therefore we need to preserve the variables defined as attributes on self. This is done by patches (callbacks) returned from this function that re-add these variables when called. Args: node: node to strip saved_attrs: collect attributes here that may need to be re-added to classes afterwards if stripping a class body (this dict is mutated)

SavedAttributes: _TypeAlias = (source)

Undocumented

Value
Dict[Tuple[ClassDef, str], SymbolTableNode]