forked from pylint-dev/pylint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
used-before-assignment
consider classes in method annotation…
… and defaults This closes pylint-dev#3771
- Loading branch information
1 parent
1daee40
commit 0f87c0e
Showing
5 changed files
with
63 additions
and
3 deletions.
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 | ||
|
||
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 |