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.
Squashed commit of the following: commit 3d7d5d3 Merge: f7333e2 27cabbb Author: Pierre Sassoulas <pierre.sassoulas@gmail.com> Date: Tue Oct 19 13:26:45 2021 +0200 Merge branch 'main' into undefined-variable commit f7333e2 Merge: 63e34c0 8e6cd18 Author: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> Date: Mon Oct 18 22:37:39 2021 +0200 Merge branch 'undefined-variable' of https://github.com/DanielNoord/pylint into undefined-variable commit 63e34c0 Author: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> Date: Mon Oct 18 22:36:32 2021 +0200 Handle `annotations` import commit 8e6cd18 Merge: c45d82e cd5838c Author: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> Date: Mon Oct 18 22:02:14 2021 +0200 Merge branch 'main' into undefined-variable commit c45d82e Author: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> Date: Mon Oct 18 20:32:06 2021 +0200 Update name and docstring commit 0f87c0e Author: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> Date: Mon Oct 18 17:45:51 2021 +0200 Make ``used-before-assignment`` consider classes in method annotation and defaults This closes pylint-dev#3771
- Loading branch information
Showing
8 changed files
with
98 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 |
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,24 @@ | ||
"""Tests for used-before-assignment with functions added in python 3.7""" | ||
# pylint: disable=missing-function-docstring | ||
from __future__ import annotations | ||
|
||
|
||
class MyClass: | ||
"""With the future import only default values can't refer to the base class""" | ||
|
||
def incorrect_method(self, other: MyClass) -> bool: | ||
return self == other | ||
|
||
def second_incorrect_method( | ||
self, other=MyClass() # [used-before-assignment] | ||
) -> bool: | ||
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[testoptions] | ||
min_pyver=3.7 |
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 @@ | ||
used-before-assignment:13:20:MyClass.second_incorrect_method:Using variable 'MyClass' before assignment:HIGH |