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

Method analyze_var_ref

mypy/checkexpr.py:447–463  ·  view source on GitHub ↗
(self, var: Var, context: Context)

Source from the content-addressed store, hash-verified

445 return AnyType(TypeOfAny.from_error)
446
447 def analyze_var_ref(self, var: Var, context: Context) -> Type:
448 if var.type:
449 var_type = get_proper_type(var.type)
450 if isinstance(var_type, Instance):
451 if var.fullname == "typing.Any":
452 # The typeshed type is 'object'; give a more useful type in runtime context
453 return self.named_type("typing._SpecialForm")
454 if self.is_literal_context() and var_type.last_known_value is not None:
455 return var_type.last_known_value
456 if var.name in {"True", "False"}:
457 return self.infer_literal_expr_type(var.name == "True", "builtins.bool")
458 return var.type
459 else:
460 if not var.is_ready and self.chk.in_checked_function():
461 self.chk.handle_cannot_determine_type(var.name, context)
462 # Implicit 'Any' type.
463 return AnyType(TypeOfAny.special_form)
464
465 def module_type(self, node: MypyFile) -> Instance:
466 try:

Callers 2

analyze_ref_exprMethod · 0.95

Calls 8

named_typeMethod · 0.95
is_literal_contextMethod · 0.95
get_proper_typeFunction · 0.90
AnyTypeClass · 0.90
isinstanceFunction · 0.85
in_checked_functionMethod · 0.45

Tested by

no test coverage detected