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

Method attribute_triggers

mypy/server/deps.py:904–932  ·  view source on GitHub ↗

Return all triggers associated with the attribute of a type.

(self, typ: Type, name: str)

Source from the content-addressed store, hash-verified

902 self.add_dependency(target)
903
904 def attribute_triggers(self, typ: Type, name: str) -> list[str]:
905 """Return all triggers associated with the attribute of a type."""
906 typ = get_proper_type(typ)
907 if isinstance(typ, TypeVarType):
908 typ = get_proper_type(typ.upper_bound)
909 if isinstance(typ, TupleType):
910 typ = typ.partial_fallback
911 if isinstance(typ, Instance):
912 member = f"{typ.type.fullname}.{name}"
913 return [make_trigger(member)]
914 elif isinstance(typ, FunctionLike) and typ.is_type_obj():
915 member = f"{typ.type_object().fullname}.{name}"
916 triggers = [make_trigger(member)]
917 triggers.extend(self.attribute_triggers(typ.fallback, name))
918 return triggers
919 elif isinstance(typ, UnionType):
920 targets = []
921 for item in typ.items:
922 targets.extend(self.attribute_triggers(item, name))
923 return targets
924 elif isinstance(typ, TypeType):
925 triggers = self.attribute_triggers(typ.item, name)
926 if isinstance(typ.item, Instance) and typ.item.type.metaclass_type is not None:
927 triggers.append(
928 make_trigger(f"{typ.item.type.metaclass_type.type.fullname}.{name}")
929 )
930 return triggers
931 else:
932 return []
933
934 def add_attribute_dependency_for_expr(self, e: Expression, name: str) -> None:
935 typ = self.type_map.get(e)

Callers 2

process_lvalueMethod · 0.95

Calls 7

get_proper_typeFunction · 0.90
make_triggerFunction · 0.90
isinstanceFunction · 0.85
extendMethod · 0.80
appendMethod · 0.80
is_type_objMethod · 0.45
type_objectMethod · 0.45

Tested by

no test coverage detected