Skip to content

Commit

Permalink
Add continue-in-finally documentation examples (#6586)
Browse files Browse the repository at this point in the history
* Add support for py-version for checker `continue-in-finally`.

Co-authored-by: Vladyslav Krylasov <vladyslav.krylasov@gmail.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
3 people authored Jun 24, 2022
1 parent 3fadb46 commit d7597c6
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 10 deletions.
5 changes: 5 additions & 0 deletions doc/data/messages/c/continue-in-finally/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
while True:
try:
pass
finally:
continue # [continue-in-finally]
2 changes: 1 addition & 1 deletion doc/data/messages/c/continue-in-finally/details.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
You can help us make the doc better `by contributing <https://github.com/PyCQA/pylint/issues/5953>`_ !
Note this message can't be emitted when using Python version 3.8 or greater.
8 changes: 7 additions & 1 deletion doc/data/messages/c/continue-in-finally/good.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# This is a placeholder for correct code for this message.
while True:
try:
pass
except ValueError:
pass
else:
continue
2 changes: 2 additions & 0 deletions doc/data/messages/c/continue-in-finally/pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MAIN]
py-version=3.7
4 changes: 2 additions & 2 deletions doc/data/messages/o/overridden-final-method/pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[testoptions]
min_pyver=3.8
[MAIN]
py-version=3.8
4 changes: 2 additions & 2 deletions doc/data/messages/s/subclassed-final-class/pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[testoptions]
min_pyver=3.8
[MAIN]
py-version=3.8
6 changes: 5 additions & 1 deletion pylint/checkers/base/basic_error_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down Expand Up @@ -492,6 +495,7 @@ def _check_in_loop(
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)

Expand Down
4 changes: 2 additions & 2 deletions tests/functional/c/continue_in_finally.rc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[testoptions]
max_pyver=3.8
[main]
py-version=3.7
2 changes: 1 addition & 1 deletion tests/functional/c/continue_in_finally.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d7597c6

Please sign in to comment.