Skip to content

Commit f6e250d

Browse files
msullivanilevkivskyi
authored andcommitted
Remove interpreted_plugin.py and all its machinery! (python#8028)
Now that mypyc supports interpreted subclasses, we can eliminate this long-winded and frumious hack.
1 parent cd18f07 commit f6e250d

File tree

4 files changed

+5
-184
lines changed

4 files changed

+5
-184
lines changed

mypy/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
from mypy.stats import dump_type_stats
5151
from mypy.types import Type
5252
from mypy.version import __version__
53-
from mypy.plugin import Plugin, ChainedPlugin, plugin_types, ReportConfigContext
53+
from mypy.plugin import Plugin, ChainedPlugin, ReportConfigContext
5454
from mypy.plugins.default import DefaultPlugin
5555
from mypy.fscache import FileSystemCache
5656
from mypy.metastore import MetadataStore, FilesystemMetadataStore, SqliteMetadataStore
@@ -423,7 +423,7 @@ def plugin_error(message: str) -> None:
423423
plugin_error(
424424
'Type object expected as the return value of "plugin"; got {!r} (in {})'.format(
425425
plugin_type, plugin_path))
426-
if not issubclass(plugin_type, plugin_types):
426+
if not issubclass(plugin_type, Plugin):
427427
plugin_error(
428428
'Return value of "plugin" must be a subclass of "mypy.plugin.Plugin" '
429429
'(in {})'.format(plugin_path))

mypy/interpreted_plugin.py

Lines changed: 0 additions & 91 deletions
This file was deleted.

mypy/plugin.py

Lines changed: 3 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,9 @@ class C: pass
119119
semantic analyzer is enabled (it's always true in mypy 0.730 and later).
120120
"""
121121

122-
import types
123-
124122
from abc import abstractmethod, abstractproperty
125123
from 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

128126
from mypy.nodes import (
129127
Expression, Context, ClassDef, SymbolTableNode, MypyFile, CallExpr
@@ -134,7 +132,6 @@ class C: pass
134132
from mypy.options import Options
135133
from mypy.lookup import lookup_fully_qualified
136134
from 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)
186183
class 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)
448446
class Plugin(CommonPluginApi):
449447
"""Base class of all type checker plugins.
450448
@@ -683,74 +681,6 @@ def get_dynamic_class_hook(self, fullname: str
683681
T = 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-
754684
class 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,)

setup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ def run(self):
9191
'sitepkgs.py',
9292
os.path.join('dmypy', '__main__.py'),
9393

94-
# Needs to be interpreted to provide a hook to interpreted plugins
95-
'interpreted_plugin.py',
96-
9794
# Uses __getattr__/__setattr__
9895
'split_namespace.py',
9996

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy