MCPcopy
hub / github.com/python/mypy / __init__

Method __init__

mypy/semanal.py:451–547  ·  view source on GitHub ↗

Construct semantic analyzer. We reuse the same semantic analyzer instance across multiple modules. Args: modules: Global modules dictionary missing_modules: Modules that could not be imported encountered so far incomplete_namespaces: Namespaces t

(
        self,
        modules: dict[str, MypyFile],
        missing_modules: dict[str, int],
        incomplete_namespaces: set[str],
        errors: Errors,
        plugin: Plugin,
        import_map: dict[str, set[str]],
    )

Source from the content-addressed store, hash-verified

449 wrapped_coro_return_types: dict[FuncDef, Type] = {}
450
451 def __init__(
452 self,
453 modules: dict[str, MypyFile],
454 missing_modules: dict[str, int],
455 incomplete_namespaces: set[str],
456 errors: Errors,
457 plugin: Plugin,
458 import_map: dict[str, set[str]],
459 ) -> None:
460 """Construct semantic analyzer.
461
462 We reuse the same semantic analyzer instance across multiple modules.
463
464 Args:
465 modules: Global modules dictionary
466 missing_modules: Modules that could not be imported encountered so far
467 incomplete_namespaces: Namespaces that are being populated during semantic analysis
468 (can contain modules and classes within the current SCC; mutated by the caller)
469 errors: Report analysis errors using this instance
470 """
471 self.locals = [None]
472 self.scope_stack = [SCOPE_GLOBAL]
473 # Saved namespaces from previous iteration. Every top-level function/method body is
474 # analyzed in several iterations until all names are resolved. We need to save
475 # the local namespaces for the top level function and all nested functions between
476 # these iterations. See also semanal_main.process_top_level_function().
477 self.saved_locals: dict[
478 FuncItem | GeneratorExpr | DictionaryComprehension, SymbolTable
479 ] = {}
480 self.imports = set()
481 self._type = None
482 self.type_stack = []
483 # Are the namespaces of classes being processed complete?
484 self.incomplete_type_stack: list[bool] = []
485 self.tvar_scope = TypeVarLikeScope()
486 self.function_stack = []
487 self.block_depth = [0]
488 self.loop_depth = [0]
489 self.errors = errors
490 self.modules = modules
491 self.import_map = import_map
492 self.msg = MessageBuilder(errors, modules)
493 self.missing_modules = missing_modules
494 self.missing_names = [set()]
495 # These namespaces are still in process of being populated. If we encounter a
496 # missing name in these namespaces, we need to defer the current analysis target,
497 # since it's possible that the name will be there once the namespace is complete.
498 self.incomplete_namespaces = incomplete_namespaces
499 self.all_exports: list[str] = []
500 self.plugin = plugin
501 self.recurse_into_functions = True
502 self.scope = Scope()
503
504 # Trace line numbers for every file where deferral happened during analysis of
505 # current SCC or top-level function.
506 self.deferral_debug_context: list[tuple[str, int]] = []
507
508 # This is needed to properly support recursive type aliases. The problem is that

Callers

nothing calls this directly

Calls 4

TypeVarLikeScopeClass · 0.90
MessageBuilderClass · 0.90
ScopeClass · 0.90
setClass · 0.85

Tested by

no test coverage detected