Support finally in continue on 3.8+

Thanks to [bpo-32489](https://bugs.python.org/issue32489) and sadly
for rejection of my [PEP 601](https://www.python.org/dev/peps/pep-0601/)
finally in continue is supported in 3.8+. I checked the blame and looks
like there was already a commit for the same subject, but that only
changes the test and not actually changes the checker (dfe7fba08e)
This commit is contained in:
Batuhan Taskaya
2020-05-22 18:32:24 +03:00
parent a3f851d8f6
commit 077e34be84
2 changed files with 20 additions and 1 deletions

View File

@@ -449,7 +449,11 @@ class _ContinueChecks(SyntaxRule):
in_loop = True
if block.type == 'try_stmt':
last_block = block.children[-3]
if last_block == 'finally' and leaf.start_pos > last_block.start_pos:
if (
last_block == "finally"
and leaf.start_pos > last_block.start_pos
and self._normalizer.version < (3, 8)
):
self.add_issue(leaf, message=self.message_in_finally)
return False # Error already added
if not in_loop:

View File

@@ -7,6 +7,8 @@ import warnings
import pytest
import parso
from textwrap import dedent
from parso._compatibility import is_pypy
from .failing_examples import FAILING_EXAMPLES, indent, build_nested
@@ -324,3 +326,16 @@ def test_invalid_fstrings(code, message):
def test_trailing_comma(code):
errors = _get_error_list(code)
assert not errors
def test_continue_in_finally():
code = dedent('''\
for a in [1]:
try:
pass
finally:
continue
''')
assert not _get_error_list(code, version="3.8")
assert _get_error_list(code, version="3.7")