Skip to content

Commit

Permalink
Add fast path to analyzing special form assignments (#16561)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JukkaL authored Nov 25, 2023
1 parent 9289a33 commit 1200d1d
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2855,22 +2855,23 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
if self.check_and_set_up_type_alias(s):
s.is_alias_def = True
special_form = True
# * type variable definition
elif self.process_typevar_declaration(s):
special_form = True
elif self.process_paramspec_declaration(s):
special_form = True
elif self.process_typevartuple_declaration(s):
special_form = True
# * type constructors
elif self.analyze_namedtuple_assign(s):
special_form = True
elif self.analyze_typeddict_assign(s):
special_form = True
elif self.newtype_analyzer.process_newtype_declaration(s):
special_form = True
elif self.analyze_enum_assign(s):
special_form = True
elif isinstance(s.rvalue, CallExpr):
# * type variable definition
if self.process_typevar_declaration(s):
special_form = True
elif self.process_paramspec_declaration(s):
special_form = True
elif self.process_typevartuple_declaration(s):
special_form = True
# * type constructors
elif self.analyze_namedtuple_assign(s):
special_form = True
elif self.analyze_typeddict_assign(s):
special_form = True
elif self.newtype_analyzer.process_newtype_declaration(s):
special_form = True
elif self.analyze_enum_assign(s):
special_form = True

if special_form:
self.record_special_form_lvalue(s)
Expand Down

0 comments on commit 1200d1d

Please sign in to comment.