-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check to make sure only strings are assigned to __name__ (#3271)
Close #583
- Loading branch information
1 parent
c4a954f
commit dc83a86
Showing
6 changed files
with
113 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -356,3 +356,5 @@ contributors: | |
* Craig Henriques: contributor | ||
|
||
* Matthijs Blom: contributor | ||
|
||
* Andy Palmer: contributor |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# pylint: disable=missing-module-docstring, missing-class-docstring | ||
# pylint: disable=too-few-public-methods, missing-function-docstring | ||
# pylint: disable=import-error | ||
|
||
import random | ||
|
||
from unknown import Unknown | ||
|
||
|
||
class ExampleClass(): | ||
pass | ||
|
||
|
||
def example_function(): | ||
pass | ||
|
||
|
||
def returns_str(): | ||
return "abcd" | ||
|
||
|
||
def returns_int(): | ||
return 0 | ||
|
||
|
||
def returns_tuple(): | ||
return 0, "abc" | ||
|
||
|
||
# Might not be thorough if same hash seed is used in testing... | ||
def returns_random_type(): | ||
if random.randint(0, 1) > 0: | ||
return 0 | ||
|
||
return "abc" | ||
|
||
ExampleClass.__name__ = 1 # [non-str-assignment-to-dunder-name] | ||
ExampleClass.__name__ = True # [non-str-assignment-to-dunder-name] | ||
ExampleClass.__name__ = returns_tuple() # [non-str-assignment-to-dunder-name] | ||
ExampleClass.__name__ = returns_int() # [non-str-assignment-to-dunder-name] | ||
ExampleClass.__name__ = "foo" | ||
ExampleClass.__name__ = returns_str() | ||
ExampleClass.__name__ = returns_random_type() | ||
ExampleClass.__name__ = Unknown | ||
|
||
example_function.__name__ = 1 # [non-str-assignment-to-dunder-name] | ||
example_function.__name__ = True # [non-str-assignment-to-dunder-name] | ||
example_function.__name__ = returns_tuple() # [non-str-assignment-to-dunder-name] | ||
example_function.__name__ = returns_int() # [non-str-assignment-to-dunder-name] | ||
example_function.__name__ = "foo" | ||
example_function.__name__ = returns_str() | ||
example_function.__name__ = returns_random_type() | ||
example_function.__name__ = Unknown |
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,8 @@ | ||
non-str-assignment-to-dunder-name:37::Non-string value assigned to __name__ | ||
non-str-assignment-to-dunder-name:38::Non-string value assigned to __name__ | ||
non-str-assignment-to-dunder-name:39::Non-string value assigned to __name__ | ||
non-str-assignment-to-dunder-name:40::Non-string value assigned to __name__ | ||
non-str-assignment-to-dunder-name:46::Non-string value assigned to __name__ | ||
non-str-assignment-to-dunder-name:47::Non-string value assigned to __name__ | ||
non-str-assignment-to-dunder-name:48::Non-string value assigned to __name__ | ||
non-str-assignment-to-dunder-name:49::Non-string value assigned to __name__ |