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

Method in_checked_function

mypy/semanal.py:7635–7659  ·  view source on GitHub ↗

Should we type-check the current function? - Yes if --check-untyped-defs is set. - Yes outside functions. - Yes in annotated functions. - No otherwise.

(self)

Source from the content-addressed store, hash-verified

7633 return self.is_defined_in_current_module(name) or "." not in name
7634
7635 def in_checked_function(self) -> bool:
7636 """Should we type-check the current function?
7637
7638 - Yes if --check-untyped-defs is set.
7639 - Yes outside functions.
7640 - Yes in annotated functions.
7641 - No otherwise.
7642 """
7643 if self.options.check_untyped_defs or not self.function_stack:
7644 return True
7645
7646 current_index = len(self.function_stack) - 1
7647 while current_index >= 0:
7648 current_func = self.function_stack[current_index]
7649 if not isinstance(current_func, LambdaExpr):
7650 return not current_func.is_dynamic()
7651
7652 # Special case, `lambda` inherits the "checked" state from its parent.
7653 # Because `lambda` itself cannot be annotated.
7654 # `lambdas` can be deeply nested, so we try to find at least one other parent.
7655 current_index -= 1
7656
7657 # This means that we only have a stack of `lambda` functions,
7658 # no regular functions.
7659 return True
7660
7661 def fail(
7662 self,

Callers 2

failMethod · 0.95
noteMethod · 0.95

Calls 3

lenFunction · 0.85
isinstanceFunction · 0.85
is_dynamicMethod · 0.45

Tested by

no test coverage detected