From 55cceba9395929fc8206f965ff8fcda22ca219c5 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Mon, 8 Nov 2021 12:09:04 -0800 Subject: [PATCH 1/3] Fix crashes with unpacking SyntaxError In general, mypy doesn't promise to be able to check the remainder of your code in the presence of syntax errors, so just make this a blocking error. Fixes #9137 Fixes #3825 (most of the reports in this issue were fixed by #8827) --- mypy/semanal.py | 3 +-- test-data/unit/check-tuples.test | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mypy/semanal.py b/mypy/semanal.py index 15f9f6be5903..a1da669378f8 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -3719,8 +3719,7 @@ def visit_dict_expr(self, expr: DictExpr) -> None: def visit_star_expr(self, expr: StarExpr) -> None: if not expr.valid: - # XXX TODO Change this error message - self.fail('Can use starred expression only as assignment target', expr) + self.fail('Can use starred expression only as assignment target', expr, blocker=True) else: expr.expr.accept(self) diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index d5b35784f5e5..b368e42e8565 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -1002,6 +1002,10 @@ b = (1, 'x') a = (0, *b, '') [builtins fixtures/tuple.pyi] +[case testUnpackSyntaxError] +*foo # E: Can use starred expression only as assignment target +[builtins fixtures/tuple.pyi] + [case testTupleMeetTupleAny] from typing import Union, Tuple class A: pass From 729bcd7f517c67449a8a40ba3557ec0a267108c9 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 14 Nov 2022 12:46:21 -0800 Subject: [PATCH 2/3] no blocking error on aiohttp --- mypy/semanal.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mypy/semanal.py b/mypy/semanal.py index 6111bbc863d2..1bc6fac1b4ad 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -1683,6 +1683,8 @@ class Foo(Bar, Generic[T]): ... declared_tvars: TypeVarLikeList = [] is_protocol = False for i, base_expr in enumerate(base_type_exprs): + if isinstance(base_expr, StarExpr): + base_expr.valid = True self.analyze_type_expr(base_expr) try: From 0b99025f20732090da11a508de300bebb3aace48 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 14 Nov 2022 12:47:53 -0800 Subject: [PATCH 3/3] add test --- test-data/unit/check-tuples.test | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index ef97f3e28687..cdb27d10fe0c 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -976,6 +976,13 @@ a = (0, *b, '') *foo # E: Can use starred expression only as assignment target [builtins fixtures/tuple.pyi] +[case testUnpackBases] +class A: ... +class B: ... +bases = (A, B) +class C(*bases): ... # E: Invalid base class +[builtins fixtures/tuple.pyi] + [case testTupleMeetTupleAny] from typing import Union, Tuple class A: pass