forked from python/mypy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterpreted_plugin.py
More file actions
91 lines (69 loc) · 3.59 KB
/
interpreted_plugin.py
File metadata and controls
91 lines (69 loc) · 3.59 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Hack for handling non-mypyc compiled plugins with a mypyc-compiled mypy"""
from typing import Optional, Callable, Any, Dict, List, Tuple
from typing_extensions import TYPE_CHECKING
from mypy.options import Options
from mypy.types import Type, CallableType
from mypy.nodes import SymbolTableNode, MypyFile
from mypy.lookup import lookup_fully_qualified
if TYPE_CHECKING:
import mypy.plugin
class InterpretedPlugin:
"""Base class of type checker plugins as exposed to external code.
This is a hack around mypyc not currently supporting interpreted subclasses
of compiled classes.
mypy.plugin will arrange for interpreted code to be find this class when it looks
for Plugin, and this class has a __new__ method that returns a WrapperPlugin object
that proxies to this interpreted version.
"""
# ... mypy doesn't like these shenanigans so we have to type ignore it!
def __new__(cls, *args: Any, **kwargs: Any) -> 'mypy.plugin.Plugin': # type: ignore
from mypy.plugin import WrapperPlugin
plugin = object.__new__(cls)
plugin.__init__(*args, **kwargs)
return WrapperPlugin(plugin)
def __init__(self, options: Options) -> None:
self.options = options
self.python_version = options.python_version
self._modules = None # type: Optional[Dict[str, MypyFile]]
def set_modules(self, modules: Dict[str, MypyFile]) -> None:
self._modules = modules
def lookup_fully_qualified(self, fullname: str) -> Optional[SymbolTableNode]:
assert self._modules is not None
return lookup_fully_qualified(fullname, self._modules)
def report_config_data(self, ctx: 'mypy.plugin.ReportConfigContext') -> Any:
return None
def get_additional_deps(self, file: MypyFile) -> List[Tuple[int, str, int]]:
return []
def get_type_analyze_hook(self, fullname: str
) -> Optional[Callable[['mypy.plugin.AnalyzeTypeContext'], Type]]:
return None
def get_function_hook(self, fullname: str
) -> Optional[Callable[['mypy.plugin.FunctionContext'], Type]]:
return None
def get_method_signature_hook(self, fullname: str
) -> Optional[Callable[['mypy.plugin.MethodSigContext'],
CallableType]]:
return None
def get_method_hook(self, fullname: str
) -> Optional[Callable[['mypy.plugin.MethodContext'], Type]]:
return None
def get_attribute_hook(self, fullname: str
) -> Optional[Callable[['mypy.plugin.AttributeContext'], Type]]:
return None
def get_class_decorator_hook(self, fullname: str
) -> Optional[Callable[['mypy.plugin.ClassDefContext'], None]]:
return None
def get_metaclass_hook(self, fullname: str
) -> Optional[Callable[['mypy.plugin.ClassDefContext'], None]]:
return None
def get_base_class_hook(self, fullname: str
) -> Optional[Callable[['mypy.plugin.ClassDefContext'], None]]:
return None
def get_customize_class_mro_hook(self, fullname: str
) -> Optional[Callable[['mypy.plugin.ClassDefContext'],
None]]:
return None
def get_dynamic_class_hook(self, fullname: str
) -> Optional[Callable[['mypy.plugin.DynamicClassDefContext'],
None]]:
return None