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

Function get_declaration

mypy/binder.py:637–650  ·  view source on GitHub ↗

Get the declared or inferred type of a RefExpr expression. Return None if there is no type or the expression is not a RefExpr. This can return None if the type hasn't been inferred yet.

(expr: BindableExpression)

Source from the content-addressed store, hash-verified

635
636
637def get_declaration(expr: BindableExpression) -> Type | None:
638 """Get the declared or inferred type of a RefExpr expression.
639
640 Return None if there is no type or the expression is not a RefExpr.
641 This can return None if the type hasn't been inferred yet.
642 """
643 if isinstance(expr, RefExpr):
644 if isinstance(expr.node, Var):
645 type = expr.node.type
646 if not isinstance(get_proper_type(type), PartialType):
647 return type
648 elif isinstance(expr.node, TypeInfo):
649 return TypeType(fill_typevars_with_any(expr.node))
650 return None
651
652
653def collapse_variadic_union(typ: UnionType) -> Type:

Callers 3

visit_del_stmtMethod · 0.90
visit_global_declMethod · 0.90
putMethod · 0.85

Calls 4

get_proper_typeFunction · 0.90
TypeTypeClass · 0.90
fill_typevars_with_anyFunction · 0.90
isinstanceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…