Utilities for comparing two versions of a module symbol table.
The goal is to find which AST nodes have externally visible changes, so that we can fire triggers and re-process other parts of the program that are stale because of the changes.
Only look at detail at definitions at the current module -- don't recurse into other modules.
A summary of the module contents:
To compare two versions of a module symbol table, take snapshots of both versions and compare the snapshots. The use of snapshots makes it easy to compare two versions of the same symbol table that is being mutated.
Summary of how this works for certain kinds of differences:
Class | SnapshotTypeVisitor |
Creates a read-only, self-contained snapshot of a type object. |
Function | compare_symbol_table_snapshots |
Return names that are different in two snapshots of a symbol table. |
Function | encode_optional_str |
Undocumented |
Function | snapshot_definition |
Create a snapshot description of a symbol table node. |
Function | snapshot_optional_type |
Undocumented |
Function | snapshot_simple_type |
Undocumented |
Function | snapshot_symbol_table |
Create a snapshot description that represents the state of a symbol table. |
Function | snapshot_type |
Create a snapshot representation of a type using nested tuples. |
Function | snapshot_types |
Undocumented |
Function | snapshot_untyped_signature |
Create a snapshot of the signature of a function that has no explicit signature. |
Variable | SnapshotItem |
Undocumented |
Return names that are different in two snapshots of a symbol table.
Only shallow (intra-module) differences are considered. References to things defined outside the module are compared based on the name of the target only.
Recurse into class symbol tables (if the class is defined in the target module).
Return a set of fully-qualified names (e.g., 'mod.func' or 'mod.Class.method').
Parameters | |
name_prefix:str | Undocumented |
snapshot1:Dict[ | Undocumented |
snapshot2:Dict[ | Undocumented |
Returns | |
Set[ | Undocumented |
Create a snapshot description of a symbol table node.
The representation is nested tuples and dicts. Only externally visible attributes are included.
Parameters | |
node:Optional[ | Undocumented |
common:Tuple[ | Undocumented |
Returns | |
Tuple[ | Undocumented |
Create a snapshot description that represents the state of a symbol table.
The snapshot has a representation based on nested tuples and dicts that makes it easy and fast to find differences.
Only "shallow" state is included in the snapshot -- references to things defined in other modules are represented just by the names of the targets.
Parameters | |
name_prefix:str | Undocumented |
table:SymbolTable | Undocumented |
Returns | |
Dict[ | Undocumented |
Parameters | |
typ:Type | Undocumented |
Returns | |
SnapshotItem | Undocumented |
Create a snapshot of the signature of a function that has no explicit signature.
If the arguments to a function without signature change, it must be considered as different. We have this special casing since we don't store the implicit signature anywhere, and we'd rather not construct new Callable objects in this module (the idea is to only read properties of the AST here).
Parameters | |
func:Union[ | Undocumented |
Returns | |
Tuple[ | Undocumented |