Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add continue-in-finally documentation examples #6586

Merged
merged 5 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)

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