From 88874a5a9fb6114cb1a8236a4f30fa2e103f91e5 Mon Sep 17 00:00:00 2001 From: Jocelyn Boullier Date: Sun, 28 Jun 2020 13:26:19 +0200 Subject: [PATCH] Fix #139: newlines in async for comprehension --- AUTHORS.txt | 1 + conftest.py | 4 ++++ parso/python/tokenize.py | 2 +- test/test_pgen2.py | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 682b0fc..4ca3d0b 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -51,6 +51,7 @@ Simon Ruggier (@sruggier) Élie Gouzien (@ElieGouzien) Tim Gates (@timgates42) Batuhan Taskaya (@isidentical) +Jocelyn Boullier (@Kazy) Note: (@user) means a github user name. diff --git a/conftest.py b/conftest.py index 654d8c1..65364bf 100644 --- a/conftest.py +++ b/conftest.py @@ -158,6 +158,10 @@ def works_ge_py35(each_version): version_info = parse_version_string(each_version) return Checker(each_version, version_info >= (3, 5)) +@pytest.fixture +def works_ge_py36(each_version): + version_info = parse_version_string(each_version) + return Checker(each_version, version_info >= (3, 6)) @pytest.fixture def works_ge_py38(each_version): diff --git a/parso/python/tokenize.py b/parso/python/tokenize.py index f8ce09a..fdcd8e0 100644 --- a/parso/python/tokenize.py +++ b/parso/python/tokenize.py @@ -260,7 +260,7 @@ def _create_token_collection(version_info): 'finally', 'while', 'with', 'return', 'continue', 'break', 'del', 'pass', 'global', 'assert') if version_info >= (3, 5): - ALWAYS_BREAK_TOKENS += ('async', 'nonlocal') + ALWAYS_BREAK_TOKENS += ('nonlocal', ) pseudo_token_compiled = _compile(PseudoToken) return TokenCollection( pseudo_token_compiled, single_quoted, triple_quoted, endpats, diff --git a/test/test_pgen2.py b/test/test_pgen2.py index 4a80922..158ec29 100644 --- a/test/test_pgen2.py +++ b/test/test_pgen2.py @@ -87,6 +87,39 @@ def test_async_for(works_ge_py35): works_ge_py35.parse("async def foo():\n async for a in b: pass") +@pytest.mark.parametrize("body", [ + """[1 async for a in b + ]""", + """[1 async + for a in b + ]""", + """[ + 1 + async for a in b + ]""", + """[ + 1 + async for a + in b + ]""", + """[ + 1 + async + for + a + in + b + ]""", + """ [ + 1 async for a in b + ]""", +]) +def test_async_for_comprehension_newline(works_ge_py36, body): + # Issue #139 + works_ge_py36.parse("""async def foo(): + {}""".format(body)) + + def test_async_with(works_ge_py35): works_ge_py35.parse("async def foo():\n async with a: pass")