Debian Codegraph @

test-data/unit/plugins/attrhook.py

raw
1 from __future__ import annotations
2
3 from typing import Callable
4
5 from mypy.plugin import AttributeContext, Plugin
6 from mypy.types import Instance, Type
7
8
9 class AttrPlugin(Plugin):
10 def get_attribute_hook(self, fullname: str) -> Callable[[AttributeContext], Type] | None:
11 if fullname == "m.Signal.__call__":
12 return signal_call_callback
13 return None
14
15
16 def signal_call_callback(ctx: AttributeContext) -> Type:
17 if isinstance(ctx.type, Instance):
18 return ctx.type.args[0]
19 return ctx.default_attr_type
20
21
22 def plugin(version: str) -> type[AttrPlugin]:
23 return AttrPlugin