Skip to content

Commit

Permalink
TypeVisitor and Co now support allow_interpreted_subclasses=True (#9602)
Browse files Browse the repository at this point in the history
Now these types can be extended from plugin code.
More context: #9001 (comment)
  • Loading branch information
sobolevn authored Oct 18, 2020
1 parent 22d2e32 commit a9fa9ab
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mypy/type_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -28,6 +28,7 @@


@trait
@mypyc_attr(allow_interpreted_subclasses=True)
class TypeVisitor(Generic[T]):
"""Visitor class for types (Type subclasses).
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit a9fa9ab

Please sign in to comment.