-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix undefined-loop-variable
with NoReturn
and Never
#7476
Merged
Pierre-Sassoulas
merged 11 commits into
pylint-dev:main
from
DanielNoord:DetachHead/main
Sep 19, 2022
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2b5e28d
fix `undefined-loop-variable` with `NoReturn` and `Never`
DetachHead 49b17b4
idk
DetachHead 70bedeb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 83cb0a3
Fix
DanielNoord c6d7b05
Use constants
DanielNoord d40e7b9
Add TODO
DanielNoord 55f0e08
Add news fragment
DanielNoord b0ed222
Revert formatting
DanielNoord 92bf4ff
Update doc/whatsnew/fragments/7311.false_positive
DanielNoord fdb6cad
Fix on lower versions
DanielNoord 370ec10
Fix
DanielNoord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Fix false positive for ``undefined-loop-variable`` in ``for-else`` loops that use a function | ||
having a return type annotation of ``NoReturn`` or ``Never``. | ||
|
||
Closes #7311 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
undefined-loop-variable:6:11:6:14:do_stuff:Using possibly undefined loop variable 'var':UNDEFINED | ||
undefined-loop-variable:25:7:25:11::Using possibly undefined loop variable 'var1':UNDEFINED | ||
undefined-loop-variable:75:11:75:14:do_stuff_with_redefined_range:Using possibly undefined loop variable 'var':UNDEFINED | ||
undefined-loop-variable:181:11:181:20:find_even_number:Using possibly undefined loop variable 'something':UNDEFINED | ||
undefined-loop-variable:14:11:14:14:do_stuff:Using possibly undefined loop variable 'var':UNDEFINED | ||
undefined-loop-variable:33:7:33:11::Using possibly undefined loop variable 'var1':UNDEFINED | ||
undefined-loop-variable:83:11:83:14:do_stuff_with_redefined_range:Using possibly undefined loop variable 'var':UNDEFINED | ||
undefined-loop-variable:201:11:201:20:find_even_number:Using possibly undefined loop variable 'something':UNDEFINED |
17 changes: 17 additions & 0 deletions
17
tests/functional/u/undefined/undefined_loop_variable_py311.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Tests for undefined-loop-variable using Python 3.11 syntax.""" | ||
|
||
from typing import Never | ||
|
||
|
||
def for_else_never(iterable): | ||
"""Test for-else with Never type.""" | ||
|
||
def idontreturn() -> Never: | ||
"""This function never returns.""" | ||
|
||
while True: | ||
for thing in iterable: | ||
break | ||
else: | ||
idontreturn() | ||
print(thing) |
2 changes: 2 additions & 0 deletions
2
tests/functional/u/undefined/undefined_loop_variable_py311.rc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[testoptions] | ||
min_pyver=3.11 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't actually infer but uses the
attrname
, which we also matchnot_typing.we_do_return.NoReturn
. That isn't really safe..