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

Function as_manager_hook

test-data/unit/plugins/dyn_class_from_method.py:51–72  ·  view source on GitHub ↗
(ctx: DynamicClassDefContext)

Source from the content-addressed store, hash-verified

49
50
51def as_manager_hook(ctx: DynamicClassDefContext) -> None:
52 class_def = ClassDef(ctx.name, Block([]))
53 class_def.fullname = ctx.api.qualified_name(ctx.name)
54
55 info = TypeInfo(SymbolTable(), class_def, ctx.api.cur_mod_id)
56 class_def.info = info
57 assert isinstance(ctx.call.callee, MemberExpr)
58 assert isinstance(ctx.call.callee.expr, IndexExpr)
59 assert isinstance(ctx.call.callee.expr.analyzed, TypeApplication)
60 assert isinstance(ctx.call.callee.expr.analyzed.expr, NameExpr)
61
62 queryset_type_fullname = ctx.call.callee.expr.analyzed.expr.fullname
63 queryset_node = ctx.api.lookup_fully_qualified_or_none(queryset_type_fullname)
64 assert queryset_node is not None
65 queryset_info = queryset_node.node
66 assert isinstance(queryset_info, TypeInfo)
67 parameter_type = ctx.call.callee.expr.analyzed.types[0]
68
69 obj = ctx.api.named_type("builtins.object")
70 info.mro = [info, queryset_info, obj.type]
71 info.bases = [Instance(queryset_info, [parameter_type])]
72 ctx.api.add_symbol_table_node(ctx.name, SymbolTableNode(GDEF, info))
73
74
75def plugin(version: str) -> type[DynPlugin]:

Callers

nothing calls this directly

Calls 11

ClassDefClass · 0.90
BlockClass · 0.90
TypeInfoClass · 0.90
SymbolTableClass · 0.90
InstanceClass · 0.90
SymbolTableNodeClass · 0.90
isinstanceFunction · 0.85
qualified_nameMethod · 0.45
named_typeMethod · 0.45
add_symbol_table_nodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…