Skip to content

Allow assignment to an empty tuple #5617

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

Merged
merged 7 commits into from
Oct 18, 2020
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
3 changes: 0 additions & 3 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2636,9 +2636,6 @@ def analyze_lvalue(self,
self.fail('Unexpected type declaration', lval)
lval.accept(self)
elif isinstance(lval, TupleExpr):
items = lval.items
if len(items) == 0 and isinstance(lval, TupleExpr):
self.fail("can't assign to ()", lval)
self.analyze_tuple_or_list_lvalue(lval, explicit_type)
elif isinstance(lval, StarExpr):
if nested:
Expand Down
3 changes: 2 additions & 1 deletion test-data/unit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Quick Start

To add a simple unit test for a new feature you developed, open or create a
`test-data/unit/check-*.test` file with a name that roughly relates to the
feature you added.
feature you added. If you added a new `check-*.test` file, add it to the list
of files in `mypy/test/testcheck.py`.

Add the test in this format anywhere in the file:

Expand Down
12 changes: 12 additions & 0 deletions test-data/unit/check-tuples.test
Original file line number Diff line number Diff line change
Expand Up @@ -1458,3 +1458,15 @@ x7, x8, y7, y8 = *points2, *points3 # E: Contiguous iterable with same type expe

x9, y9, x10, y10, z5 = *points2, 1, *points2 # E: Contiguous iterable with same type expected
[builtins fixtures/tuple.pyi]

[case testAssignEmptyPy36]
# flags: --python-version 3.6
() = []

[case testAssignEmptyPy27]
# flags: --python-version 2.7
() = [] # E: can't assign to ()

[case testAssignEmptyBogus]
() = 1 # E: 'Literal[1]?' object is not iterable
[builtins fixtures/tuple.pyi]
5 changes: 0 additions & 5 deletions test-data/unit/semanal-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,6 @@ main:1: error: can't assign to literal
[out]
main:1: error: can't assign to literal

[case testInvalidLvalues5]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this still be an error saying 1 is not iterable or similar?

Also, I would like to see a new test that does things like () = [] or a, () = list() and asserts that there are no errors.

() = 1
[out]
main:1: error: can't assign to ()

[case testInvalidLvalues6]
x = y = z = 1 # ok
x, (y, 1) = 1
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy