Skip to content

Commit afd5a38

Browse files
authored
perf: add __slots__ to SubtypeVisitor (#19394)
We construct quite a lot of them. This made a selfcheck benchmark 0.4-0.7% faster when run on my local PC.
1 parent cb3bddd commit afd5a38

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

mypy/subtypes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,15 @@ def check_type_parameter(
390390

391391

392392
class SubtypeVisitor(TypeVisitor[bool]):
393+
__slots__ = (
394+
"right",
395+
"orig_right",
396+
"proper_subtype",
397+
"subtype_context",
398+
"options",
399+
"_subtype_kind",
400+
)
401+
393402
def __init__(self, right: Type, subtype_context: SubtypeContext, proper_subtype: bool) -> None:
394403
self.right = get_proper_type(right)
395404
self.orig_right = right

0 commit comments

Comments
 (0)