-
-
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
Make used-before-assignment
consider classes in method annotation and defaults
#5184
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0f87c0e
Make ``used-before-assignment`` consider classes in method annotation…
DanielNoord c45d82e
Update name and docstring
DanielNoord 8e6cd18
Merge branch 'main' into undefined-variable
DanielNoord 63e34c0
Handle `annotations` import
DanielNoord f7333e2
Merge branch 'undefined-variable' of https://github.com/DanielNoord/p…
DanielNoord 3d7d5d3
Merge branch 'main' into undefined-variable
Pierre-Sassoulas 8a3e33f
Changes after code review
DanielNoord 46c21e3
Merge branch 'undefined-variable' of https://github.com/DanielNoord/p…
DanielNoord 645b2c7
Apply suggestions from code review
DanielNoord 9b76224
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6b9a024
Apply suggestions from code review
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
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,8 +1,26 @@ | ||
"""pylint doesn't see the NameError in this module""" | ||
#pylint: disable=consider-using-f-string | ||
#pylint: disable=consider-using-f-string, missing-function-docstring | ||
__revision__ = None | ||
|
||
MSG = "hello %s" % MSG # [used-before-assignment] | ||
|
||
MSG2 = ("hello %s" % | ||
MSG2) # [used-before-assignment] | ||
|
||
|
||
class MyClass: | ||
"""Type annotation or default values for first level methods can't refer to their own class""" | ||
def incorrect_method(self, other: MyClass) -> bool: # [used-before-assignment] | ||
return self == other | ||
cdce8p marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def second_incorrect_method(self, other = MyClass()) -> bool: # [used-before-assignment] | ||
return self == other | ||
|
||
def correct_method(self, other: "MyClass") -> bool: | ||
return self == other | ||
|
||
def second_correct_method(self) -> bool: | ||
def inner_method(self, other: MyClass) -> bool: | ||
return self == other | ||
|
||
return inner_method(self, MyClass()) |
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,2 +1,4 @@ | ||
used-before-assignment:5:19::Using variable 'MSG' before assignment | ||
used-before-assignment:8:8::Using variable 'MSG2' before assignment | ||
used-before-assignment:5:19::Using variable 'MSG' before assignment:HIGH | ||
used-before-assignment:8:8::Using variable 'MSG2' before assignment:HIGH | ||
used-before-assignment:13:38:MyClass.incorrect_method:Using variable 'MyClass' before assignment:HIGH | ||
used-before-assignment:16:46:MyClass.second_incorrect_method:Using variable 'MyClass' 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.
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 for loop spanning 200 lines asks for a refactor. Maybe you have an idea on how we could simplify this ? I'm not saying we should refactor it now.
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.
It's awful. I don't even understand half of what it is doing and variable names such as
maybee0601
really don't help.One of the problems is that it is doing something with
consuming
variables in different scopes which I don't really understand. We can probably investigate this at some point.I'm just going through the open issues for
undefined-variable
as it seemed like a good addition to2.12
to improve that checker. For now I tend to add new single-purposemethods
andelifs
, that should help refactoring 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.
Glad to see I'm not the only one 😄 Yes the consuming + continue + break makes the refactor quite hard. Also it's really hard to understand what's happening, good job fixing issues despite that 🎉
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.
The complete
visit_name
function has just gotten too complicated. Not sure we'll ever be able to fix it though. It's really easy to break things if something goes wrong during the refactor. Lot's of testing needed before then.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.
It is also because the way consumption works is quite difficult to understand. It took me a while to understand how the actual looping over scopes works. If we were to improve that (or it explanation) I think we would already be in a much better place.