@@ -119,11 +119,9 @@ class C: pass
119119semantic analyzer is enabled (it's always true in mypy 0.730 and later).
120120"""
121121
122- import types
123-
124122from abc import abstractmethod , abstractproperty
125123from typing import Any , Callable , List , Tuple , Optional , NamedTuple , TypeVar , Dict
126- from mypy_extensions import trait
124+ from mypy_extensions import trait , mypyc_attr
127125
128126from mypy .nodes import (
129127 Expression , Context , ClassDef , SymbolTableNode , MypyFile , CallExpr
@@ -134,7 +132,6 @@ class C: pass
134132from mypy .options import Options
135133from mypy .lookup import lookup_fully_qualified
136134from mypy .errorcodes import ErrorCode
137- import mypy .interpreted_plugin
138135
139136
140137@trait
@@ -182,7 +179,7 @@ def analyze_callable_args(self, arglist: TypeList) -> Optional[Tuple[List[Type],
182179 ('api' , TypeAnalyzerPluginInterface )])
183180
184181
185- @trait
182+ @mypyc_attr ( allow_interpreted_subclasses = True )
186183class CommonPluginApi :
187184 """
188185 A common plugin API (shared between semantic analysis and type checking phases)
@@ -445,6 +442,7 @@ def final_iteration(self) -> bool:
445442 ])
446443
447444
445+ @mypyc_attr (allow_interpreted_subclasses = True )
448446class Plugin (CommonPluginApi ):
449447 """Base class of all type checker plugins.
450448
@@ -683,74 +681,6 @@ def get_dynamic_class_hook(self, fullname: str
683681T = TypeVar ('T' )
684682
685683
686- class WrapperPlugin (Plugin ):
687- """A plugin that wraps an interpreted plugin.
688-
689- This is a ugly workaround the limitation that mypyc-compiled
690- classes can't be subclassed by interpreted ones, so instead we
691- create a new class for interpreted clients to inherit from and
692- dispatch to it from here.
693-
694- Eventually mypyc ought to do something like this automatically.
695- """
696-
697- def __init__ (self , plugin : mypy .interpreted_plugin .InterpretedPlugin ) -> None :
698- super ().__init__ (plugin .options )
699- self .plugin = plugin
700-
701- def set_modules (self , modules : Dict [str , MypyFile ]) -> None :
702- self .plugin .set_modules (modules )
703-
704- def lookup_fully_qualified (self , fullname : str ) -> Optional [SymbolTableNode ]:
705- return self .plugin .lookup_fully_qualified (fullname )
706-
707- def report_config_data (self , ctx : ReportConfigContext ) -> Any :
708- return self .plugin .report_config_data (ctx )
709-
710- def get_additional_deps (self , file : MypyFile ) -> List [Tuple [int , str , int ]]:
711- return self .plugin .get_additional_deps (file )
712-
713- def get_type_analyze_hook (self , fullname : str
714- ) -> Optional [Callable [[AnalyzeTypeContext ], Type ]]:
715- return self .plugin .get_type_analyze_hook (fullname )
716-
717- def get_function_hook (self , fullname : str
718- ) -> Optional [Callable [[FunctionContext ], Type ]]:
719- return self .plugin .get_function_hook (fullname )
720-
721- def get_method_signature_hook (self , fullname : str
722- ) -> Optional [Callable [[MethodSigContext ], CallableType ]]:
723- return self .plugin .get_method_signature_hook (fullname )
724-
725- def get_method_hook (self , fullname : str
726- ) -> Optional [Callable [[MethodContext ], Type ]]:
727- return self .plugin .get_method_hook (fullname )
728-
729- def get_attribute_hook (self , fullname : str
730- ) -> Optional [Callable [[AttributeContext ], Type ]]:
731- return self .plugin .get_attribute_hook (fullname )
732-
733- def get_class_decorator_hook (self , fullname : str
734- ) -> Optional [Callable [[ClassDefContext ], None ]]:
735- return self .plugin .get_class_decorator_hook (fullname )
736-
737- def get_metaclass_hook (self , fullname : str
738- ) -> Optional [Callable [[ClassDefContext ], None ]]:
739- return self .plugin .get_metaclass_hook (fullname )
740-
741- def get_base_class_hook (self , fullname : str
742- ) -> Optional [Callable [[ClassDefContext ], None ]]:
743- return self .plugin .get_base_class_hook (fullname )
744-
745- def get_customize_class_mro_hook (self , fullname : str
746- ) -> Optional [Callable [[ClassDefContext ], None ]]:
747- return self .plugin .get_customize_class_mro_hook (fullname )
748-
749- def get_dynamic_class_hook (self , fullname : str
750- ) -> Optional [Callable [[DynamicClassDefContext ], None ]]:
751- return self .plugin .get_dynamic_class_hook (fullname )
752-
753-
754684class ChainedPlugin (Plugin ):
755685 """A plugin that represents a sequence of chained plugins.
756686
@@ -831,18 +761,3 @@ def _find_hook(self, lookup: Callable[[Plugin], T]) -> Optional[T]:
831761 if hook :
832762 return hook
833763 return None
834-
835-
836- def _dummy () -> None :
837- """Only used to test whether we are running in compiled mode."""
838-
839-
840- # This is an incredibly frumious hack. If this module is compiled by mypyc,
841- # set the module 'Plugin' attribute to point to InterpretedPlugin. This means
842- # that anything interpreted that imports Plugin will get InterpretedPlugin
843- # while anything compiled alongside this module will get the real Plugin.
844- if isinstance (_dummy , types .BuiltinFunctionType ):
845- plugin_types = (Plugin , mypy .interpreted_plugin .InterpretedPlugin ) # type: Tuple[type, ...]
846- globals ()['Plugin' ] = mypy .interpreted_plugin .InterpretedPlugin
847- else :
848- plugin_types = (Plugin ,)
0 commit comments