MCPcopy Create free account
hub / github.com/python/mypy / get_partial_self_var

Method get_partial_self_var

mypy/checkexpr.py:1087–1107  ·  view source on GitHub ↗

Get variable node for a partial self attribute. If the expression is not a self attribute, or attribute is not variable, or variable is not partial, return None.

(self, expr: MemberExpr)

Source from the content-addressed store, hash-verified

1085 return orig_ret_type
1086
1087 def get_partial_self_var(self, expr: MemberExpr) -> Var | None:
1088 """Get variable node for a partial self attribute.
1089
1090 If the expression is not a self attribute, or attribute is not variable,
1091 or variable is not partial, return None.
1092 """
1093 if not (
1094 isinstance(expr.expr, NameExpr)
1095 and isinstance(expr.expr.node, Var)
1096 and expr.expr.node.is_self
1097 ):
1098 # Not a self.attr expression.
1099 return None
1100 info = self.chk.scope.enclosing_class()
1101 if not info or expr.name not in info.names:
1102 # Don't mess with partial types in superclasses.
1103 return None
1104 sym = info.names[expr.name]
1105 if isinstance(sym.node, Var) and isinstance(sym.node.type, PartialType):
1106 return sym.node
1107 return None
1108
1109 # Types and methods that can be used to infer partial types.
1110 item_args: ClassVar[dict[str, list[str]]] = {

Calls 2

isinstanceFunction · 0.85
enclosing_classMethod · 0.80

Tested by

no test coverage detected