diff --git a/doc/data/messages/c/continue-in-finally/bad.py b/doc/data/messages/c/continue-in-finally/bad.py new file mode 100644 index 0000000000..190463f5a0 --- /dev/null +++ b/doc/data/messages/c/continue-in-finally/bad.py @@ -0,0 +1,5 @@ +while True: + try: + pass + finally: + continue # [continue-in-finally] diff --git a/doc/data/messages/c/continue-in-finally/details.rst b/doc/data/messages/c/continue-in-finally/details.rst index ab82045295..2d9044ee1a 100644 --- a/doc/data/messages/c/continue-in-finally/details.rst +++ b/doc/data/messages/c/continue-in-finally/details.rst @@ -1 +1 @@ -You can help us make the doc better `by contributing `_ ! +Note this message can't be emitted when using Python version 3.8 or greater. diff --git a/doc/data/messages/c/continue-in-finally/good.py b/doc/data/messages/c/continue-in-finally/good.py index c40beb573f..6b14ef4462 100644 --- a/doc/data/messages/c/continue-in-finally/good.py +++ b/doc/data/messages/c/continue-in-finally/good.py @@ -1 +1,7 @@ -# This is a placeholder for correct code for this message. +while True: + try: + pass + except ValueError: + pass + else: + continue diff --git a/doc/data/messages/c/continue-in-finally/pylintrc b/doc/data/messages/c/continue-in-finally/pylintrc new file mode 100644 index 0000000000..b7a429f3d4 --- /dev/null +++ b/doc/data/messages/c/continue-in-finally/pylintrc @@ -0,0 +1,2 @@ +[MAIN] +py-version=3.7 diff --git a/doc/data/messages/o/overridden-final-method/pylintrc b/doc/data/messages/o/overridden-final-method/pylintrc index 85fc502b37..a711c25d12 100644 --- a/doc/data/messages/o/overridden-final-method/pylintrc +++ b/doc/data/messages/o/overridden-final-method/pylintrc @@ -1,2 +1,2 @@ -[testoptions] -min_pyver=3.8 +[MAIN] +py-version=3.8 diff --git a/doc/data/messages/s/subclassed-final-class/pylintrc b/doc/data/messages/s/subclassed-final-class/pylintrc index 85fc502b37..a711c25d12 100644 --- a/doc/data/messages/s/subclassed-final-class/pylintrc +++ b/doc/data/messages/s/subclassed-final-class/pylintrc @@ -1,2 +1,2 @@ -[testoptions] -min_pyver=3.8 +[MAIN] +py-version=3.8 diff --git a/pylint/checkers/base/basic_error_checker.py b/pylint/checkers/base/basic_error_checker.py index ad70b26f51..38a9aa9f0e 100644 --- a/pylint/checkers/base/basic_error_checker.py +++ b/pylint/checkers/base/basic_error_checker.py @@ -189,7 +189,6 @@ class BasicErrorChecker(_BasicChecker): "continue-in-finally", "Emitted when the `continue` keyword is found " "inside a finally clause, which is a SyntaxError.", - {"maxversion": (3, 8)}, ), "E0117": ( "nonlocal name %s found without binding", @@ -206,6 +205,10 @@ class BasicErrorChecker(_BasicChecker): ), } + def open(self) -> None: + py_version = self.linter.config.py_version + self._py38_plus = py_version >= (3, 8) + @utils.only_required_for_messages("function-redefined") def visit_classdef(self, node: nodes.ClassDef) -> None: self._check_redefinition("class", node) @@ -490,6 +493,7 @@ def _check_in_loop(self, node, node_name): isinstance(parent, nodes.TryFinally) and node in parent.finalbody and isinstance(node, nodes.Continue) + and not self._py38_plus ): self.add_message("continue-in-finally", node=node) diff --git a/tests/functional/c/continue_in_finally.rc b/tests/functional/c/continue_in_finally.rc index 67a28a36aa..77eb3be645 100644 --- a/tests/functional/c/continue_in_finally.rc +++ b/tests/functional/c/continue_in_finally.rc @@ -1,2 +1,2 @@ -[testoptions] -max_pyver=3.8 +[main] +py-version=3.7 diff --git a/tests/functional/c/continue_in_finally.txt b/tests/functional/c/continue_in_finally.txt index 3a5e542e1a..a427b33691 100644 --- a/tests/functional/c/continue_in_finally.txt +++ b/tests/functional/c/continue_in_finally.txt @@ -1 +1 @@ -continue-in-finally:9:::'continue' not supported inside 'finally' clause +continue-in-finally:9:8:9:16::'continue' not supported inside 'finally' clause:UNDEFINED