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 1 commit
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
Next Next commit
remove check and update tests
  • Loading branch information
Tobin Yehle committed Sep 13, 2018
commit 2993591e6467bf94d79a703eb65b70199a6ae56c
3 changes: 0 additions & 3 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2074,9 +2074,6 @@ def analyze_lvalue(self, lval: Lvalue, nested: bool = False,
if not add_global:
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, add_global, explicit_type)
elif isinstance(lval, StarExpr):
if nested:
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/semanal-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ MypyFile:1(
NameExpr(f [__main__.f])
Args())))

[case testAssignEmptyTuple]
Copy link
Member

Choose a reason for hiding this comment

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

Not sure we need this test; these tests that print out internal data structures are harder to maintain and harder to map to user-visible behavior.

() = 1
[out]
MypyFile:1(
AssignmentStmt:1(
TupleExpr:1()
IntExpr(1)))


[case testAccessingGlobalNameBeforeDefinition]
x
f()
Expand Down
5 changes: 0 additions & 5 deletions test-data/unit/semanal-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,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