-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix used-before-assignment
false positive for TYPE_CHECKING if/elif/else usage
#8071
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
Merged
Pierre-Sassoulas
merged 21 commits into
pylint-dev:main
from
zenlyj:false_positive_type_checking
Feb 7, 2023
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0acdd1d
Fix type checking used-before-assignment false positive
zenlyj 6f85bb9
Add functional tests
zenlyj cce327a
Merge branch 'main' of https://github.com/PyCQA/pylint into false_posβ¦
zenlyj d99dd81
Add changelog
zenlyj 19d2681
Revert unnecessary changes
zenlyj 51090bd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 775ccc9
Add utility function to detect name definition recursively
zenlyj bf72993
Update tests to handle more cases
zenlyj 04a091d
Merge branch 'main' of https://github.com/PyCQA/pylint into false_posβ¦
zenlyj c594f75
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4aafcae
Resolve CI errors
zenlyj 318f30d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 35576ea
Update comment for easier understanding
zenlyj 352d6de
Debug is_defined check for except handler name
zenlyj d1dc39b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0904a52
[cosmetic] Alphabetize imports in functional test
zenlyj 58bdfff
Shift walrus functional tests to dedicated py38 test file
zenlyj 1198e5b
[cosmetic] Rename functions in functional test
zenlyj 4acf0f6
Minor refactor to improve code readability
zenlyj 2fc8fda
Remove exception handler name check in utils.is_defined
zenlyj c24f62a
Merge branch 'main' of https://github.com/PyCQA/pylint into false_posβ¦
zenlyj 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 hidden or 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 ``used-before-assignment`` when | ||
``typing.TYPE_CHECKING`` is used with if/elif/else blocks. | ||
|
||
Closes #7574 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,11 +1,11 @@ | ||
used-before-assignment:17:15:17:18:typing_and_self_referencing_assignment_expression:Using variable 'var' before assignment:HIGH | ||
used-before-assignment:23:15:23:18:self_referencing_assignment_expression:Using variable 'var' before assignment:HIGH | ||
undefined-variable:48:6:48:16::Undefined variable 'no_default':UNDEFINED | ||
undefined-variable:56:6:56:22::Undefined variable 'again_no_default':UNDEFINED | ||
undefined-variable:82:6:82:19::Undefined variable 'else_assign_1':INFERENCE | ||
undefined-variable:105:6:105:19::Undefined variable 'else_assign_2':INFERENCE | ||
used-before-assignment:140:10:140:16:type_annotation_used_improperly_after_comprehension:Using variable 'my_int' before assignment:HIGH | ||
used-before-assignment:147:10:147:16:type_annotation_used_improperly_after_comprehension_2:Using variable 'my_int' before assignment:HIGH | ||
used-before-assignment:177:12:177:16:expression_in_ternary_operator_inside_container_wrong_position:Using variable 'val3' before assignment:HIGH | ||
used-before-assignment:181:9:181:10::Using variable 'z' before assignment:HIGH | ||
used-before-assignment:188:6:188:19::Using variable 'NEVER_DEFINED' before assignment:CONTROL_FLOW | ||
used-before-assignment:18:15:18:18:typing_and_self_referencing_assignment_expression:Using variable 'var' before assignment:HIGH | ||
used-before-assignment:24:15:24:18:self_referencing_assignment_expression:Using variable 'var' before assignment:HIGH | ||
undefined-variable:49:6:49:16::Undefined variable 'no_default':UNDEFINED | ||
undefined-variable:57:6:57:22::Undefined variable 'again_no_default':UNDEFINED | ||
undefined-variable:83:6:83:19::Undefined variable 'else_assign_1':INFERENCE | ||
undefined-variable:106:6:106:19::Undefined variable 'else_assign_2':INFERENCE | ||
used-before-assignment:141:10:141:16:type_annotation_used_improperly_after_comprehension:Using variable 'my_int' before assignment:HIGH | ||
used-before-assignment:148:10:148:16:type_annotation_used_improperly_after_comprehension_2:Using variable 'my_int' before assignment:HIGH | ||
used-before-assignment:178:12:178:16:expression_in_ternary_operator_inside_container_wrong_position:Using variable 'val3' before assignment:HIGH | ||
used-before-assignment:182:9:182:10::Using variable 'z' before assignment:HIGH | ||
used-before-assignment:189:6:189:19::Using variable 'NEVER_DEFINED' before assignment:CONTROL_FLOW |
This file contains hidden or 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 hidden or 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,5 +1,5 @@ | ||
undefined-variable:17:21:17:28:MyClass.incorrect_typing_method:Undefined variable 'MyClass':UNDEFINED | ||
undefined-variable:22:26:22:33:MyClass.incorrect_nested_typing_method:Undefined variable 'MyClass':UNDEFINED | ||
undefined-variable:27:20:27:27:MyClass.incorrect_default_method:Undefined variable 'MyClass':UNDEFINED | ||
used-before-assignment:88:35:88:39:MyFourthClass.is_close:Using variable 'math' before assignment:HIGH | ||
used-before-assignment:101:20:101:28:VariableAnnotationsGuardedByTypeChecking:Using variable 'datetime' before assignment:HIGH | ||
undefined-variable:68:21:68:28:MyClass.incorrect_typing_method:Undefined variable 'MyClass':UNDEFINED | ||
undefined-variable:73:26:73:33:MyClass.incorrect_nested_typing_method:Undefined variable 'MyClass':UNDEFINED | ||
undefined-variable:78:20:78:27:MyClass.incorrect_default_method:Undefined variable 'MyClass':UNDEFINED | ||
used-before-assignment:139:35:139:39:MyFourthClass.is_close:Using variable 'math' before assignment:HIGH | ||
used-before-assignment:152:20:152:28:VariableAnnotationsGuardedByTypeChecking:Using variable 'datetime' before assignment:HIGH |
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.
Uh oh!
There was an error while loading. Please reload this page.