8000 Fix crashes with unpacking SyntaxError (#11499) · python/mypy@e0a37fa · GitHub
[go: up one dir, main page]

Skip to content

Commit e0a37fa

Browse files
authored
Fix crashes with unpacking SyntaxError (#11499)
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) Co-authored-by: hauntsaninja <>
1 parent dd0503e commit e0a37fa

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

mypy/semanal.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,8 @@ class Foo(Bar, Generic[T]): ...
16831683
declared_tvars: TypeVarLikeList = []
16841684
is_protocol = False
16851685
for i, base_expr in enumerate(base_type_exprs):
1686+
if isinstance(base_expr, StarExpr):
1687+
base_expr.valid = True
16861688
self.analyze_type_expr(base_expr)
16871689

16881690
try:
@@ -4539,8 +4541,7 @@ def visit_dict_expr(self, expr: DictExpr) -> None:
45394541

45404542
def visit_star_expr(self, expr: StarExpr) -> None:
45414543
if not expr.valid:
4542-
# XXX TODO Change this error message
4543-
self.fail("Can use starred expression only as assignment target", expr)
4544+
self.fail("Can use starred expression only as assignment target", expr, blocker=True)
45444545
else:
45454546
expr.expr.accept(self)
45464547

test-data/unit/check-tuples.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,17 @@ b = (1, 'x')
972972
a = (0, *b, '')
973973
[builtins fixtures/tuple.pyi]
974974

975+
[case testUnpackSyntaxError]
976+
*foo # E: Can use starred expression only as assignment target
977+
[builtins fixtures/tuple.pyi]
978+
979+
[case testUnpackBases]
980+
class A: ...
981+
class B: ...
982+
bases = (A, B)
983+
class C(*bases): ... # E: Invalid base class
984+
[builtins fixtures/tuple.pyi]
985+
975986
[case testTupleMeetTupleAny]
976987
from typing import Union, Tuple
977988
class A: pass

0 commit comments

Comments
 (0)
0