Fix #139: newlines in async for comprehension

This commit is contained in:
Jocelyn Boullier
2020-06-28 13:26:19 +02:00
parent 7e0586b0b9
commit 88874a5a9f
4 changed files with 39 additions and 1 deletions

View File

@@ -51,6 +51,7 @@ Simon Ruggier (@sruggier)
Élie Gouzien (@ElieGouzien) Élie Gouzien (@ElieGouzien)
Tim Gates (@timgates42) <tim.gates@iress.com> Tim Gates (@timgates42) <tim.gates@iress.com>
Batuhan Taskaya (@isidentical) <isidentical@gmail.com> Batuhan Taskaya (@isidentical) <isidentical@gmail.com>
Jocelyn Boullier (@Kazy) <jocelyn@boullier.bzh>
Note: (@user) means a github user name. Note: (@user) means a github user name.

View File

@@ -158,6 +158,10 @@ def works_ge_py35(each_version):
version_info = parse_version_string(each_version) version_info = parse_version_string(each_version)
return Checker(each_version, version_info >= (3, 5)) 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 @pytest.fixture
def works_ge_py38(each_version): def works_ge_py38(each_version):

View File

@@ -260,7 +260,7 @@ def _create_token_collection(version_info):
'finally', 'while', 'with', 'return', 'continue', 'finally', 'while', 'with', 'return', 'continue',
'break', 'del', 'pass', 'global', 'assert') 'break', 'del', 'pass', 'global', 'assert')
if version_info >= (3, 5): if version_info >= (3, 5):
ALWAYS_BREAK_TOKENS += ('async', 'nonlocal') ALWAYS_BREAK_TOKENS += ('nonlocal', )
pseudo_token_compiled = _compile(PseudoToken) pseudo_token_compiled = _compile(PseudoToken)
return TokenCollection( return TokenCollection(
pseudo_token_compiled, single_quoted, triple_quoted, endpats, pseudo_token_compiled, single_quoted, triple_quoted, endpats,

View File

@@ -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") 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): def test_async_with(works_ge_py35):
works_ge_py35.parse("async def foo():\n async with a: pass") works_ge_py35.parse("async def foo():\n async with a: pass")