From d4f11d877066fa734d7a10550a1beaae80c268a9 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Sat, 11 Nov 2023 15:24:20 +0000 Subject: [PATCH] Add fast path to analyzing special form assignments 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. --- mypy/semanal.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/mypy/semanal.py b/mypy/semanal.py index 6714e8c56de9..1020718eef61 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -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)