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

Method visit_member_expr

mypy/server/deps.py:665–696  ·  view source on GitHub ↗
(self, e: MemberExpr)

Source from the content-addressed store, hash-verified

663 self.process_global_ref_expr(o)
664
665 def visit_member_expr(self, e: MemberExpr) -> None:
666 if isinstance(e.expr, RefExpr) and isinstance(e.expr.node, TypeInfo):
667 # Special case class attribute so that we don't depend on "__init__".
668 self.add_dependency(make_trigger(e.expr.node.fullname))
669 else:
670 super().visit_member_expr(e)
671 if e.kind is not None:
672 # Reference to a module attribute
673 self.process_global_ref_expr(e)
674 else:
675 # Reference to a non-module (or missing) attribute
676 if e.expr not in self.type_map:
677 # No type available -- this happens for unreachable code. Since it's unreachable,
678 # it wasn't type checked and we don't need to generate dependencies.
679 return
680 if isinstance(e.expr, RefExpr) and isinstance(e.expr.node, MypyFile):
681 # Special case: reference to a missing module attribute.
682 self.add_dependency(make_trigger(e.expr.node.fullname + "." + e.name))
683 return
684 typ = get_proper_type(self.type_map[e.expr])
685 self.add_attribute_dependency(typ, e.name)
686 if self.use_logical_deps() and isinstance(typ, AnyType):
687 name = self.get_unimported_fullname(e, typ)
688 if name is not None:
689 # Generate a logical dependency from an unimported
690 # definition (which comes from a missing module).
691 # Example:
692 # import missing # "missing" not in build
693 #
694 # def g() -> None:
695 # missing.f() # Generate dependency from "missing.f"
696 self.add_dependency(make_trigger(name))
697
698 def get_unimported_fullname(self, e: MemberExpr, typ: AnyType) -> str | None:
699 """If e refers to an unimported definition, infer the fullname of this.

Callers

nothing calls this directly

Calls 8

add_dependencyMethod · 0.95
use_logical_depsMethod · 0.95
make_triggerFunction · 0.90
get_proper_typeFunction · 0.90
isinstanceFunction · 0.85

Tested by

no test coverage detected