Skip to content

Commit 48f2b10

Browse files
authored
Allow assignment to an empty tuple (python#5617)
1 parent f5f5485 commit 48f2b10

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

mypy/semanal.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,9 +2640,6 @@ def analyze_lvalue(self,
26402640
self.fail('Unexpected type declaration', lval)
26412641
lval.accept(self)
26422642
elif isinstance(lval, TupleExpr):
2643-
items = lval.items
2644-
if len(items) == 0 and isinstance(lval, TupleExpr):
2645-
self.fail("can't assign to ()", lval)
26462643
self.analyze_tuple_or_list_lvalue(lval, explicit_type)
26472644
elif isinstance(lval, StarExpr):
26482645
if nested:

test-data/unit/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Quick Start
77

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

1213
Add the test in this format anywhere in the file:
1314

test-data/unit/check-tuples.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,3 +1458,15 @@ x7, x8, y7, y8 = *points2, *points3 # E: Contiguous iterable with same type expe
14581458

14591459
x9, y9, x10, y10, z5 = *points2, 1, *points2 # E: Contiguous iterable with same type expected
14601460
[builtins fixtures/tuple.pyi]
1461+
1462+
[case testAssignEmptyPy36]
1463+
# flags: --python-version 3.6
1464+
() = []
1465+
1466+
[case testAssignEmptyPy27]
1467+
# flags: --python-version 2.7
1468+
() = [] # E: can't assign to ()
1469+
1470+
[case testAssignEmptyBogus]
1471+
() = 1 # E: 'Literal[1]?' object is not iterable
1472+
[builtins fixtures/tuple.pyi]

test-data/unit/semanal-errors.test

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,6 @@ main:1: error: can't assign to literal
377377
[out]
378378
main:1: error: can't assign to literal
379379

380-
[case testInvalidLvalues5]
381-
() = 1
382-
[out]
383-
main:1: error: can't assign to ()
384-
385380
[case testInvalidLvalues6]
386381
x = y = z = 1 # ok
387382
x, (y, 1) = 1

0 commit comments

Comments
 (0)
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