-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge the empty-string extensions to 'implicit_booleaness_checker'
- Loading branch information
1 parent
a8b8b39
commit c1bb4f8
Showing
20 changed files
with
115 additions
and
150 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/bad.py
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,6 @@ | ||
def important_string_manipulation(x: str, y: str) -> None: | ||
if x == "": # [use-implicit-booleaness-not-comparison-to-string] | ||
print("x is an empty string") | ||
|
||
if y != "": # [use-implicit-booleaness-not-comparison-to-string] | ||
print("y is not an empty string") |
3 changes: 3 additions & 0 deletions
3
doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/details.rst
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,3 @@ | ||
Following this check blindly in weakly typed code base can create hard to debug issues. If the value | ||
can be something else that is falsey but not a string (for example ``None``, or ``0``), the code will | ||
not be equivalent. |
6 changes: 6 additions & 0 deletions
6
doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/good.py
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,6 @@ | ||
def important_string_manipulation(x: str, y: str) -> None: | ||
if not x: | ||
print("x is an empty string") | ||
|
||
if y: | ||
print("y is not an empty string") |
2 changes: 2 additions & 0 deletions
2
doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/pylintrc
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 @@ | ||
[main] | ||
enable=use-implicit-booleaness-not-comparison-to-string |
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
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,12 +1,14 @@ | ||
* The compare to empty string checker (``pylint.extensions.emptystring``) has been removed and its checks are | ||
* The compare to empty string checker (``pylint.extensions.emptystring``) and the compare to | ||
zero checker (``pylint.extensions.compare-to-zero``) have been removed and their checks are | ||
now part of the implicit booleaness checker: | ||
|
||
- ``compare-to-zero`` was renamed ``use-implicit-booleaness-not-comparison-to-zero`` | ||
and it now need to be enabled explicitly. | ||
- The ``pylint.extensions.compare-to-zero`` extension no longer exists and | ||
and ``compare-to-empty-string`` was renamed ``use-implicit-booleaness-not-comparison-to-string`` | ||
and they now need to be enabled explicitly. | ||
- The `pylint.extensions.emptystring`` and ``pylint.extensions.compare-to-zero`` extensions no longer exists and | ||
needs to be removed from the ``load-plugins`` option. | ||
|
||
This permits to make the likeness explicit and will provide better performance as they share most of their | ||
This permits to make their likeness explicit and will provide better performance as they share most of their | ||
conditions to be raised. | ||
|
||
Refs #6871 |
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 was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
tests/functional/ext/emptystring/empty_string_comparison.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.py
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,22 @@ | ||
# pylint: disable=literal-comparison,missing-docstring | ||
|
||
X = '' | ||
Y = 'test' | ||
|
||
if X is '': # [use-implicit-booleaness-not-comparison-to-string] | ||
pass | ||
|
||
if Y is not "": # [use-implicit-booleaness-not-comparison-to-string] | ||
pass | ||
|
||
if X == "": # [use-implicit-booleaness-not-comparison-to-string] | ||
pass | ||
|
||
if Y != '': # [use-implicit-booleaness-not-comparison-to-string] | ||
pass | ||
|
||
if "" == Y: # [use-implicit-booleaness-not-comparison-to-string] | ||
pass | ||
|
||
if '' != X: # [use-implicit-booleaness-not-comparison-to-string] | ||
pass |
2 changes: 2 additions & 0 deletions
2
tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.rc
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 @@ | ||
[MAIN] | ||
enable=use-implicit-booleaness-not-comparison-to-string |
6 changes: 6 additions & 0 deletions
6
tests/functional/u/use/use_implicit_booleaness_not_comparison_to_string.txt
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,6 @@ | ||
use-implicit-booleaness-not-comparison-to-string:6:3:6:10::"""X is ''"" can be simplified to ""not X"" as an empty string is falsey":HIGH | ||
use-implicit-booleaness-not-comparison-to-string:9:3:9:14::"""Y is not ''"" can be simplified to ""Y"" as an empty string is falsey":HIGH | ||
use-implicit-booleaness-not-comparison-to-string:12:3:12:10::"""X == ''"" can be simplified to ""not X"" as an empty string is falsey":HIGH | ||
use-implicit-booleaness-not-comparison-to-string:15:3:15:10::"""Y != ''"" can be simplified to ""Y"" as an empty string is falsey":HIGH | ||
use-implicit-booleaness-not-comparison-to-string:18:3:18:10::"""'' == Y"" can be simplified to ""not Y"" as an empty string is falsey":HIGH | ||
use-implicit-booleaness-not-comparison-to-string:21:3:21:10::"""'' != X"" can be simplified to ""X"" as an empty string is falsey":HIGH |