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

Method enter

mypy/semanal.py:7409–7432  ·  view source on GitHub ↗

Enter a function, generator or comprehension scope.

(
        self, function: FuncItem | GeneratorExpr | DictionaryComprehension
    )

Source from the content-addressed store, hash-verified

7407
7408 @contextmanager
7409 def enter(
7410 self, function: FuncItem | GeneratorExpr | DictionaryComprehension
7411 ) -> Iterator[None]:
7412 """Enter a function, generator or comprehension scope."""
7413 names = self.saved_locals.setdefault(function, SymbolTable())
7414 self.locals.append(names)
7415 is_comprehension = isinstance(function, (GeneratorExpr, DictionaryComprehension))
7416 self.scope_stack.append(SCOPE_FUNC if not is_comprehension else SCOPE_COMPREHENSION)
7417 self.global_decls.append(set())
7418 self.nonlocal_decls.append(set())
7419 # -1 since entering block will increment this to 0.
7420 self.block_depth.append(-1)
7421 self.loop_depth.append(0)
7422 self.missing_names.append(set())
7423 try:
7424 yield
7425 finally:
7426 self.locals.pop()
7427 self.scope_stack.pop()
7428 self.global_decls.pop()
7429 self.nonlocal_decls.pop()
7430 self.block_depth.pop()
7431 self.loop_depth.pop()
7432 self.missing_names.pop()
7433
7434 def is_func_scope(self) -> bool:
7435 scope_type = self.scope_stack[-1]

Callers 3

analyze_function_bodyMethod · 0.95
visit_generator_exprMethod · 0.95

Calls 6

SymbolTableClass · 0.90
isinstanceFunction · 0.85
setClass · 0.85
setdefaultMethod · 0.80
appendMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected