Skip to content

Commit

Permalink
Fix crashes with unpacking SyntaxError
Browse files Browse the repository at this point in the history
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 python#9137
Fixes python#3825 (most of the reports in this issue were fixed by python#8827)
  • Loading branch information
hauntsaninja committed Nov 8, 2021
1 parent dda64db commit 55cceba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions test-data/unit/check-tuples.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55cceba

Please sign in to comment.