The semantic analyzer.
Bind names to definitions and do various other simple consistency checks. Populate symbol tables. The semantic analyzer also detects special forms which reuse generic syntax such as NamedTuple and cast(). Multiple analysis iterations may be needed to analyze forward references and import cycles. Each iteration "fills in" additional bindings and references until everything has been bound.
For example, consider this program:
x = 1 y = x
Here semantic analysis would detect that the assignment 'x = 1' defines a new variable, the type of which is to be inferred (in a later pass; type inference or type checking is not part of semantic analysis). Also, it would bind both references to 'x' to the same module-level variable (Var) node. The second assignment would also be analyzed, and the type of 'y' marked as being inferred.
Semantic analysis of types is implemented in typeanal.py.
See semanal_main.py for the top-level logic.
Some important properties:
Class | HasPlaceholders |
Undocumented |
Class | MakeAnyNonExplicit |
Undocumented |
Class | SemanticAnalyzer |
Semantically analyze parsed mypy files. |
Function | apply_semantic_analyzer_patches |
Call patch callbacks in the right order. |
Function | dummy_context |
Undocumented |
Function | find_duplicate |
If the list has duplicates, return one of the duplicates. |
Function | has_placeholder |
Check if a type contains any placeholder types (recursively). |
Function | is_same_symbol |
Undocumented |
Function | is_same_var_from_getattr |
Do n1 and n2 refer to the same Var derived from module-level __getattr__? |
Function | is_valid_replacement |
Can symbol table node replace an existing one? |
Function | make_any_non_explicit |
Replace all Any types within in with Any that has attribute 'explicit' set to False |
Function | names_modified_by_assignment |
Return all unqualified (short) names assigned to in an assignment statement. |
Function | names_modified_in_lvalue |
Return all NameExpr assignment targets in an Lvalue. |
Function | refers_to_class_or_function |
Does semantically analyzed node refer to a class? |
Function | refers_to_fullname |
Is node a name or member expression with the given full name? |
Function | remove_imported_names_from_symtable |
Remove all imported names from the symbol table of a module. |
Function | replace_implicit_first_type |
Undocumented |
Constant | CORE_BUILTIN_CLASSES |
Undocumented |
Constant | FUTURE_IMPORTS |
Undocumented |
Constant | T |
Undocumented |
Call patch callbacks in the right order.
This should happen after semantic analyzer pass 3.
Parameters | |
patches:List[ | Undocumented |
Parameters | |
typ:Type | Undocumented |
Returns | |
bool | Undocumented |
Undocumented
Parameters | |
a:Optional[ | Undocumented |
b:Optional[ | Undocumented |
Returns | |
bool | Undocumented |
Parameters | |
n1:Optional[ | Undocumented |
n2:Optional[ | Undocumented |
Returns | |
bool | Undocumented |
Can symbol table node replace an existing one?
These are the only valid cases:
Parameters | |
old:SymbolTableNode | Undocumented |
new:SymbolTableNode | Undocumented |
Returns | |
bool | Undocumented |
Parameters | |
s:AssignmentStmt | Undocumented |
Returns | |
List[ | Undocumented |
Parameters | |
lvalue:Lvalue | Undocumented |
Returns | |
List[ | Undocumented |
Parameters | |
node:Expression | Undocumented |
Returns | |
bool | Undocumented |
Parameters | |
node:Expression | Undocumented |
fullname:str | Undocumented |
Returns | |
bool | Undocumented |
Parameters | |
names:SymbolTable | Undocumented |
module:str | Undocumented |
Undocumented
Parameters | |
sig:FunctionLike | Undocumented |
new:Type | Undocumented |
Returns | |
FunctionLike | Undocumented |
Undocumented
Value |
|