From 077e34be849548fdf9d7a478cf04f83e63e5555b Mon Sep 17 00:00:00 2001 From: Batuhan Taskaya Date: Fri, 22 May 2020 18:32:24 +0300 Subject: [PATCH] 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 (dfe7fba08e993b4c0f2e0af75f81e787fc399297) --- parso/python/errors.py | 6 +++++- test/test_python_errors.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/parso/python/errors.py b/parso/python/errors.py index a944191..b0cc29a 100644 --- a/parso/python/errors.py +++ b/parso/python/errors.py @@ -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: diff --git a/test/test_python_errors.py b/test/test_python_errors.py index 3f6dde7..bf00d57 100644 --- a/test/test_python_errors.py +++ b/test/test_python_errors.py @@ -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") + +