From 2993591e6467bf94d79a703eb65b70199a6ae56c Mon Sep 17 00:00:00 2001 From: Tobin Yehle Date: Thu, 13 Sep 2018 12:19:29 -0600 Subject: [PATCH 1/5] remove check and update tests --- mypy/semanal.py | 3 --- test-data/unit/semanal-basic.test | 9 +++++++++ test-data/unit/semanal-errors.test | 5 ----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/mypy/semanal.py b/mypy/semanal.py index 212bfe698c672..350d5bb16e265 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -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: diff --git a/test-data/unit/semanal-basic.test b/test-data/unit/semanal-basic.test index 238544ff8ea9f..646df36954518 100644 --- a/test-data/unit/semanal-basic.test +++ b/test-data/unit/semanal-basic.test @@ -47,6 +47,15 @@ MypyFile:1( NameExpr(f [__main__.f]) Args()))) +[case testAssignEmptyTuple] +() = 1 +[out] +MypyFile:1( + AssignmentStmt:1( + TupleExpr:1() + IntExpr(1))) + + [case testAccessingGlobalNameBeforeDefinition] x f() diff --git a/test-data/unit/semanal-errors.test b/test-data/unit/semanal-errors.test index b1f6e6e750dfa..7ed57f5a6cf13 100644 --- a/test-data/unit/semanal-errors.test +++ b/test-data/unit/semanal-errors.test @@ -373,11 +373,6 @@ main:1: error: can't assign to literal [out] main:1: error: can't assign to literal -[case testInvalidLvalues5] -() = 1 -[out] -main:1: error: can't assign to () - [case testInvalidLvalues6] x = y = z = 1 # ok x, (y, 1) = 1 From 52e44cb9df4adac97f2be224b2d69b2f75b268a9 Mon Sep 17 00:00:00 2001 From: Tobin Yehle Date: Thu, 13 Sep 2018 12:21:17 -0600 Subject: [PATCH 2/5] remove extra line --- test-data/unit/semanal-basic.test | 1 - 1 file changed, 1 deletion(-) diff --git a/test-data/unit/semanal-basic.test b/test-data/unit/semanal-basic.test index 646df36954518..9bb098513acce 100644 --- a/test-data/unit/semanal-basic.test +++ b/test-data/unit/semanal-basic.test @@ -55,7 +55,6 @@ MypyFile:1( TupleExpr:1() IntExpr(1))) - [case testAccessingGlobalNameBeforeDefinition] x f() From 28aae4b30e741f8571af2c7390bac30150c4f57e Mon Sep 17 00:00:00 2001 From: Tobin Yehle Date: Thu, 3 Jan 2019 15:02:00 -0700 Subject: [PATCH 3/5] add the tests I would like to have --- mypy/test/testcheck.py | 1 + test-data/unit/README.md | 3 ++- test-data/unit/check-assign-tuple.test | 15 +++++++++++++++ test-data/unit/semanal-basic.test | 8 -------- 4 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 test-data/unit/check-assign-tuple.test diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index 7f8de5bbbb3e8..247b0aedc91ce 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -23,6 +23,7 @@ # List of files that contain test case descriptions. typecheck_files = [ + 'check-assign-tuple.test', 'check-basic.test', 'check-callable.test', 'check-classes.test', diff --git a/test-data/unit/README.md b/test-data/unit/README.md index 3c95a3e0f67ed..002513614f250 100644 --- a/test-data/unit/README.md +++ b/test-data/unit/README.md @@ -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: diff --git a/test-data/unit/check-assign-tuple.test b/test-data/unit/check-assign-tuple.test new file mode 100644 index 0000000000000..502a594cbc2d1 --- /dev/null +++ b/test-data/unit/check-assign-tuple.test @@ -0,0 +1,15 @@ +[case testAssignTupleNonIterable] +() = 1 #E: 'builtins.int' object is not iterable +[typing fixtures/typing-full.pyi] + +[case testAssignEmptyPy36] +# flags: --python-version 3.6 +() = [] + +[case testAssignEmptyPy35] +# flags: --python-version 3.5 +() = [] # E: can't assign to () + +[case testAssignEmptyPy27] +# flags: --python-version 2.7 +() = [] # E: can't assign to () \ No newline at end of file diff --git a/test-data/unit/semanal-basic.test b/test-data/unit/semanal-basic.test index 9bb098513acce..238544ff8ea9f 100644 --- a/test-data/unit/semanal-basic.test +++ b/test-data/unit/semanal-basic.test @@ -47,14 +47,6 @@ MypyFile:1( NameExpr(f [__main__.f]) Args()))) -[case testAssignEmptyTuple] -() = 1 -[out] -MypyFile:1( - AssignmentStmt:1( - TupleExpr:1() - IntExpr(1))) - [case testAccessingGlobalNameBeforeDefinition] x f() From 25fab94a1eadf6f49075bf7998701d786d8cf28f Mon Sep 17 00:00:00 2001 From: Tobin Yehle Date: Thu, 3 Jan 2019 15:07:56 -0700 Subject: [PATCH 4/5] remove failing tests --- test-data/unit/check-assign-tuple.test | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test-data/unit/check-assign-tuple.test b/test-data/unit/check-assign-tuple.test index 502a594cbc2d1..134e33db30e20 100644 --- a/test-data/unit/check-assign-tuple.test +++ b/test-data/unit/check-assign-tuple.test @@ -1,15 +1,7 @@ -[case testAssignTupleNonIterable] -() = 1 #E: 'builtins.int' object is not iterable -[typing fixtures/typing-full.pyi] - [case testAssignEmptyPy36] # flags: --python-version 3.6 () = [] -[case testAssignEmptyPy35] -# flags: --python-version 3.5 -() = [] # E: can't assign to () - [case testAssignEmptyPy27] # flags: --python-version 2.7 () = [] # E: can't assign to () \ No newline at end of file From a3dd53b2217c4eba35ccaa375a81901c10145724 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Sat, 17 Oct 2020 20:30:06 -0700 Subject: [PATCH 5/5] cleanup, add test --- mypy/test/testcheck.py | 1 - test-data/unit/check-assign-tuple.test | 7 ------- test-data/unit/check-tuples.test | 12 ++++++++++++ 3 files changed, 12 insertions(+), 8 deletions(-) delete mode 100644 test-data/unit/check-assign-tuple.test diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index 95d3f26d3735a..34d9b66da0c14 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -24,7 +24,6 @@ # List of files that contain test case descriptions. typecheck_files = [ - 'check-assign-tuple.test', 'check-basic.test', 'check-callable.test', 'check-classes.test', diff --git a/test-data/unit/check-assign-tuple.test b/test-data/unit/check-assign-tuple.test deleted file mode 100644 index 134e33db30e20..0000000000000 --- a/test-data/unit/check-assign-tuple.test +++ /dev/null @@ -1,7 +0,0 @@ -[case testAssignEmptyPy36] -# flags: --python-version 3.6 -() = [] - -[case testAssignEmptyPy27] -# flags: --python-version 2.7 -() = [] # E: can't assign to () \ No newline at end of file diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index ec3c2bc48c1b5..55bee11b699fb 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -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]