Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashes with unpacking SyntaxError #11499

Merged
merged 4 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -4539,8 +4541,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
11 changes: 11 additions & 0 deletions test-data/unit/check-tuples.test
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,17 @@ 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 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
Expand Down