Debian Codegraph @

test-data/unit/plugins/class_attr_hook.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 Type as MypyType
7
8
9 class ClassAttrPlugin(Plugin):
10 def get_class_attribute_hook(
11 self, fullname: str
12 ) -> Callable[[AttributeContext], MypyType] | None:
13 if fullname == "__main__.Cls.attr":
14 return my_hook
15 return None
16
17
18 def my_hook(ctx: AttributeContext) -> MypyType:
19 return ctx.api.named_generic_type("builtins.int", [])
20
21
22 def plugin(_version: str) -> type[ClassAttrPlugin]:
23 return ClassAttrPlugin