From 95a7c3ade0aec0ac8143e80c2f41b557bc5206e6 Mon Sep 17 00:00:00 2001 From: Vlad Emelianov Date: Wed, 30 Oct 2019 13:30:31 +0100 Subject: [PATCH 1/5] Use testlist_star_expr in return_stmt grammar --- blib2to3/Grammar.txt | 2 +- tests/data/python38.py | 17 +++++++++++++++++ tests/test_black.py | 12 ++++-------- 3 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 tests/data/python38.py diff --git a/blib2to3/Grammar.txt b/blib2to3/Grammar.txt index d90710f6eef..01596dc7342 100644 --- a/blib2to3/Grammar.txt +++ b/blib2to3/Grammar.txt @@ -89,7 +89,7 @@ pass_stmt: 'pass' flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt break_stmt: 'break' continue_stmt: 'continue' -return_stmt: 'return' [testlist] +return_stmt: 'return' [testlist_star_expr] yield_stmt: yield_expr raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]] import_stmt: import_name | import_from diff --git a/tests/data/python38.py b/tests/data/python38.py new file mode 100644 index 00000000000..6a3e254a587 --- /dev/null +++ b/tests/data/python38.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3.8 + + +def starred_return(): + my_list = ["test", "test2"] + return "asd", *my_list + + +# output + + +#!/usr/bin/env python3.8 + + +def starred_return(): + my_list = ["test", "test2"] + return "asd", *my_list diff --git a/tests/test_black.py b/tests/test_black.py index 93f853bae4f..9648efa9d89 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -584,19 +584,15 @@ def test_async_as_identifier(self) -> None: self.invokeBlack([str(source_path), "--target-version", "py37"], exit_code=123) @patch("black.dump_to_file", dump_to_stderr) - def test_python37(self) -> None: - source_path = (THIS_DIR / "data" / "python37.py").resolve() - source, expected = read_data("python37") + def test_python38(self) -> None: + source_path = (THIS_DIR / "data" / "python38.py").resolve() + source, expected = read_data("python38") actual = fs(source) self.assertFormatEqual(expected, actual) major, minor = sys.version_info[:2] - if major > 3 or (major == 3 and minor >= 7): + if major > 3 or (major == 3 and minor >= 8): black.assert_equivalent(source, actual) black.assert_stable(source, actual, black.FileMode()) - # ensure black can parse this when the target is 3.7 - self.invokeBlack([str(source_path), "--target-version", "py37"]) - # but not on 3.6, because we use async as a reserved keyword - self.invokeBlack([str(source_path), "--target-version", "py36"], exit_code=123) @patch("black.dump_to_file", dump_to_stderr) def test_fmtonoff(self) -> None: From 76f70f22e8e454b8f6cd05986ad884d6be489fe2 Mon Sep 17 00:00:00 2001 From: Vlad Emelianov Date: Wed, 30 Oct 2019 13:35:58 +0100 Subject: [PATCH 2/5] Change values in test --- tests/data/python38.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/data/python38.py b/tests/data/python38.py index 6a3e254a587..75e19ba112e 100644 --- a/tests/data/python38.py +++ b/tests/data/python38.py @@ -2,8 +2,8 @@ def starred_return(): - my_list = ["test", "test2"] - return "asd", *my_list + my_list = ["value2", "value3"] + return "value1", *my_list # output @@ -13,5 +13,5 @@ def starred_return(): def starred_return(): - my_list = ["test", "test2"] - return "asd", *my_list + my_list = ["value2", "value3"] + return "value1", *my_list From 3aa4f4659ce7f28e83c6d47aa983f9e8c40a03c9 Mon Sep 17 00:00:00 2001 From: Vlad Emelianov Date: Wed, 30 Oct 2019 13:51:26 +0100 Subject: [PATCH 3/5] Add support for starred yield --- blib2to3/Grammar.txt | 2 +- tests/data/python38.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/blib2to3/Grammar.txt b/blib2to3/Grammar.txt index 01596dc7342..f14e2b516bd 100644 --- a/blib2to3/Grammar.txt +++ b/blib2to3/Grammar.txt @@ -212,4 +212,4 @@ testlist1: test (',' test)* encoding_decl: NAME yield_expr: 'yield' [yield_arg] -yield_arg: 'from' test | testlist +yield_arg: 'from' test | testlist_star_expr diff --git a/tests/data/python38.py b/tests/data/python38.py index 75e19ba112e..1a7f76167d9 100644 --- a/tests/data/python38.py +++ b/tests/data/python38.py @@ -6,6 +6,11 @@ def starred_return(): return "value1", *my_list +def starred_yield(): + my_list = ["value2", "value3"] + yield "value1", *my_list + + # output @@ -15,3 +20,8 @@ def starred_return(): def starred_return(): my_list = ["value2", "value3"] return "value1", *my_list + + +def starred_yield(): + my_list = ["value2", "value3"] + yield "value1", *my_list From adec6c79359a7adfce7073e335027e598588d0df Mon Sep 17 00:00:00 2001 From: Vlad Emelianov Date: Wed, 30 Oct 2019 16:43:10 +0100 Subject: [PATCH 4/5] Readd deleted python37 test --- tests/test_black.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_black.py b/tests/test_black.py index 9648efa9d89..150398be8bc 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -583,6 +583,21 @@ def test_async_as_identifier(self) -> None: # but not on 3.7, because async/await is no longer an identifier self.invokeBlack([str(source_path), "--target-version", "py37"], exit_code=123) + @patch("black.dump_to_file", dump_to_stderr) + def test_python37(self) -> None: + source_path = (THIS_DIR / "data" / "python37.py").resolve() + source, expected = read_data("python37") + actual = fs(source) + self.assertFormatEqual(expected, actual) + major, minor = sys.version_info[:2] + if major > 3 or (major == 3 and minor >= 7): + black.assert_equivalent(source, actual) + black.assert_stable(source, actual, black.FileMode()) + # ensure black can parse this when the target is 3.7 + self.invokeBlack([str(source_path), "--target-version", "py37"]) + # but not on 3.6, because we use async as a reserved keyword + self.invokeBlack([str(source_path), "--target-version", "py36"], exit_code=123) + @patch("black.dump_to_file", dump_to_stderr) def test_python38(self) -> None: source_path = (THIS_DIR / "data" / "python38.py").resolve() From ff05d808a1ddffa8c1d453bf4aa6f65408f6e3c4 Mon Sep 17 00:00:00 2001 From: Vlad Emelianov Date: Wed, 30 Oct 2019 17:12:20 +0100 Subject: [PATCH 5/5] Remove unused source_path --- tests/test_black.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_black.py b/tests/test_black.py index 150398be8bc..245a82546b9 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -600,7 +600,6 @@ def test_python37(self) -> None: @patch("black.dump_to_file", dump_to_stderr) def test_python38(self) -> None: - source_path = (THIS_DIR / "data" / "python38.py").resolve() source, expected = read_data("python38") actual = fs(source) self.assertFormatEqual(expected, actual)