forked from wandb/weave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mypy_weave_plugin.py
33 lines (24 loc) · 982 Bytes
/
mypy_weave_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Weave plugin for mypy.
@weave.type() is a decorator that behaves like Python's @dataclasess.dataclass().
This tells mypy to treat it as such.
"""
from typing import Optional, Callable
from mypy.plugin import ClassDefContext, Plugin
class WeavePlugin(Plugin):
def get_class_decorator_hook(
self, fullname: str
) -> Optional[Callable[[ClassDefContext], None]]:
from mypy.plugins import dataclasses
if fullname in ["weave.decorator_type.type"]:
return dataclasses.dataclass_tag_callback
return None
def get_class_decorator_hook_2(
self, fullname: str
) -> Optional[Callable[[ClassDefContext], bool]]:
from mypy.plugins import dataclasses
if fullname in ["weave.decorator_type.type"]:
return dataclasses.dataclass_class_maker_callback
return None
def plugin(version: str):
# ignore version argument if the plugin works with all mypy versions.
return WeavePlugin