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

Class SemanticAnalyzer

mypy/semanal.py:375–8202  ·  view source on GitHub ↗

Semantically analyze parsed mypy files. The analyzer binds names and does various consistency checks for an AST. Note that type checking is performed as a separate pass.

Source from the content-addressed store, hash-verified

373
374
375class SemanticAnalyzer(
376 NodeVisitor[None], SemanticAnalyzerInterface, SemanticAnalyzerPluginInterface, SplittingVisitor
377):
378 """Semantically analyze parsed mypy files.
379
380 The analyzer binds names and does various consistency checks for an
381 AST. Note that type checking is performed as a separate pass.
382 """
383
384 __deletable__ = ["patches", "options", "cur_mod_node"]
385
386 # Module name space
387 modules: dict[str, MypyFile]
388 # Global name space for current module
389 globals: SymbolTable
390 # Names declared using "global" (separate set for each scope)
391 global_decls: list[set[str]]
392 # Names declared using "nonlocal" (separate set for each scope)
393 nonlocal_decls: list[set[str]]
394 # Local names of function scopes; None for non-function scopes.
395 locals: list[SymbolTable | None]
396 # Type of each scope (SCOPE_*, indexes match locals)
397 scope_stack: list[int]
398 # Nested block depths of scopes
399 block_depth: list[int]
400 # TypeInfo of directly enclosing class (or None)
401 _type: TypeInfo | None = None
402 # Stack of outer classes (the second tuple item contains tvars).
403 type_stack: list[TypeInfo | None]
404 # Type variables bound by the current scope, be it class or function
405 tvar_scope: TypeVarLikeScope
406 # Per-module options
407 options: Options
408
409 # Stack of functions being analyzed
410 function_stack: list[FuncItem]
411
412 # Set to True if semantic analysis defines a name, or replaces a
413 # placeholder definition. If some iteration makes no progress,
414 # there can be at most one additional final iteration (see below).
415 progress = False
416 deferred = False # Set to true if another analysis pass is needed
417 incomplete = False # Set to true if current module namespace is missing things
418 # Is this the final iteration of semantic analysis (where we report
419 # unbound names due to cyclic definitions and should not defer)?
420 _final_iteration = False
421 # These names couldn't be added to the symbol table due to incomplete deps.
422 # Note that missing names are per module, _not_ per namespace. This means that e.g.
423 # a missing name at global scope will block adding same name at a class scope.
424 # This should not affect correctness and is purely a performance issue,
425 # since it can cause unnecessary deferrals. These are represented as
426 # PlaceholderNodes in the symbol table. We use this to ensure that the first
427 # definition takes precedence even if it's incomplete.
428 #
429 # Note that a star import adds a special name '*' to the set, this blocks
430 # adding _any_ names in the current file.
431 missing_names: list[set[str]]
432 # Callbacks that will be called after semantic analysis to tweak things.

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…