Skip to content

Commit 1200d1d

Browse files
authored
Add fast path to analyzing special form assignments (python#16561)
This showed up as hot spot in a CPU profile collected when running tests. This makes `mypy/test/testcheck.py` about 2% faster on my Linux desktop.
1 parent 9289a33 commit 1200d1d

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

mypy/semanal.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,22 +2855,23 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
28552855
if self.check_and_set_up_type_alias(s):
28562856
s.is_alias_def = True
28572857
special_form = True
2858-
# * type variable definition
2859-
elif self.process_typevar_declaration(s):
2860-
special_form = True
2861-
elif self.process_paramspec_declaration(s):
2862-
special_form = True
2863-
elif self.process_typevartuple_declaration(s):
2864-
special_form = True
2865-
# * type constructors
2866-
elif self.analyze_namedtuple_assign(s):
2867-
special_form = True
2868-
elif self.analyze_typeddict_assign(s):
2869-
special_form = True
2870-
elif self.newtype_analyzer.process_newtype_declaration(s):
2871-
special_form = True
2872-
elif self.analyze_enum_assign(s):
2873-
special_form = True
2858+
elif isinstance(s.rvalue, CallExpr):
2859+
# * type variable definition
2860+
if self.process_typevar_declaration(s):
2861+
special_form = True
2862+
elif self.process_paramspec_declaration(s):
2863+
special_form = True
2864+
elif self.process_typevartuple_declaration(s):
2865+
special_form = True
2866+
# * type constructors
2867+
elif self.analyze_namedtuple_assign(s):
2868+
special_form = True
2869+
elif self.analyze_typeddict_assign(s):
2870+
special_form = True
2871+
elif self.newtype_analyzer.process_newtype_declaration(s):
2872+
special_form = True
2873+
elif self.analyze_enum_assign(s):
2874+
special_form = True
28742875

28752876
if special_form:
28762877
self.record_special_form_lvalue(s)

0 commit comments

Comments
 (0)