From 975fcc59ae757ca24861e8dacd2e738194aa6e0d Mon Sep 17 00:00:00 2001 From: Mark Byrne Date: Wed, 11 May 2022 23:39:08 +0200 Subject: [PATCH 1/4] Add `continue-in-finally` documentation examples based on the `pylint-errors project. Co-authored-by: Vladyslav Krylasov --- doc/data/messages/c/continue-in-finally/bad.py | 5 +++++ doc/data/messages/c/continue-in-finally/good.py | 7 +++++++ doc/data/messages/c/continue-in-finally/pylintrc | 2 ++ 3 files changed, 14 insertions(+) create mode 100644 doc/data/messages/c/continue-in-finally/bad.py create mode 100644 doc/data/messages/c/continue-in-finally/good.py create mode 100644 doc/data/messages/c/continue-in-finally/pylintrc 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/good.py b/doc/data/messages/c/continue-in-finally/good.py new file mode 100644 index 0000000000..6b14ef4462 --- /dev/null +++ b/doc/data/messages/c/continue-in-finally/good.py @@ -0,0 +1,7 @@ +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..67a28a36aa --- /dev/null +++ b/doc/data/messages/c/continue-in-finally/pylintrc @@ -0,0 +1,2 @@ +[testoptions] +max_pyver=3.8 From ad7781970673b0ded9a80a7600fe630119e34301 Mon Sep 17 00:00:00 2001 From: Mark Byrne Date: Sat, 14 May 2022 22:36:39 +0200 Subject: [PATCH 2/4] Add `details.rst` & test against Python 3.7. --- doc/data/messages/c/continue-in-finally/details.rst | 1 + doc/data/messages/c/continue-in-finally/pylintrc | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 doc/data/messages/c/continue-in-finally/details.rst diff --git a/doc/data/messages/c/continue-in-finally/details.rst b/doc/data/messages/c/continue-in-finally/details.rst new file mode 100644 index 0000000000..2d9044ee1a --- /dev/null +++ b/doc/data/messages/c/continue-in-finally/details.rst @@ -0,0 +1 @@ +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/pylintrc b/doc/data/messages/c/continue-in-finally/pylintrc index 67a28a36aa..b7a429f3d4 100644 --- a/doc/data/messages/c/continue-in-finally/pylintrc +++ b/doc/data/messages/c/continue-in-finally/pylintrc @@ -1,2 +1,2 @@ -[testoptions] -max_pyver=3.8 +[MAIN] +py-version=3.7 From 487034a023e4c976ef83aa53e22632f48a52ffa7 Mon Sep 17 00:00:00 2001 From: Mark Byrne Date: Sat, 14 May 2022 22:39:38 +0200 Subject: [PATCH 3/4] `min_pyver` is an unrecognized option: `min_pyver` -> `py-version`. --- doc/data/messages/o/overridden-final-method/pylintrc | 4 ++-- doc/data/messages/s/subclassed-final-class/pylintrc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 From a689344dbc5089cbe53bf2cadb49961c8268ab6b Mon Sep 17 00:00:00 2001 From: Mark Byrne Date: Fri, 24 Jun 2022 19:53:18 +0200 Subject: [PATCH 4/4] Add support for py-version for checker `continue-in-finally`. --- pylint/checkers/base/basic_error_checker.py | 6 +++++- tests/functional/c/continue_in_finally.rc | 4 ++-- tests/functional/c/continue_in_finally.txt | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) 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