From 45451f2cd1eaf754441a5277e13373c3bccbf4de Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Fri, 16 Oct 2020 21:09:38 +0300 Subject: [PATCH] TypeVisitor and Co now support allow_interpreted_subclasses=True Now these types can be extended from plugin code. More context: https://github.com/python/mypy/issues/9001#issuecomment-710315985 --- mypy/type_visitor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mypy/type_visitor.py b/mypy/type_visitor.py index 06b44bd497f0..8a95ceb049af 100644 --- a/mypy/type_visitor.py +++ b/mypy/type_visitor.py @@ -14,7 +14,7 @@ from abc import abstractmethod from mypy.ordered_dict import OrderedDict from typing import Generic, TypeVar, cast, Any, List, Callable, Iterable, Optional, Set, Sequence -from mypy_extensions import trait +from mypy_extensions import trait, mypyc_attr T = TypeVar('T') @@ -28,6 +28,7 @@ @trait +@mypyc_attr(allow_interpreted_subclasses=True) class TypeVisitor(Generic[T]): """Visitor class for types (Type subclasses). @@ -104,6 +105,7 @@ def visit_type_alias_type(self, t: TypeAliasType) -> T: @trait +@mypyc_attr(allow_interpreted_subclasses=True) class SyntheticTypeVisitor(TypeVisitor[T]): """A TypeVisitor that also knows how to visit synthetic AST constructs. @@ -134,6 +136,7 @@ def visit_placeholder_type(self, t: PlaceholderType) -> T: pass +@mypyc_attr(allow_interpreted_subclasses=True) class TypeTranslator(TypeVisitor[Type]): """Identity type transformation. @@ -241,6 +244,7 @@ def visit_type_alias_type(self, t: TypeAliasType) -> Type: pass +@mypyc_attr(allow_interpreted_subclasses=True) class TypeQuery(SyntheticTypeVisitor[T]): """Visitor for performing queries of types.