-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Merge use implicit booleaness like checks #8630
Merged
Pierre-Sassoulas
merged 3 commits into
pylint-dev:main
from
Pierre-Sassoulas:merge-use-implicite-booleaness-like-checks
May 2, 2023
+268
−330
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
8535f3b
Merge the compare-to-zero extensions to 'implicit_booleaness_checker'
Pierre-Sassoulas 7da156e
Merge the empty-string extensions to 'implicit_booleaness_checker'
Pierre-Sassoulas 2526ec9
[doc] Add warning for empty sequences in 'use-implicit-booleaness-not…
Pierre-Sassoulas 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
Merge the empty-string extensions to 'implicit_booleaness_checker'
commit 7da156e7978662edd3ccb616cbf9b4e12f65061b
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 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -634,6 +634,10 @@ | |
"mails": ["[email protected]"], | ||
"name": "Boris Feld" | ||
}, | ||
"[email protected]": { | ||
"mails": ["[email protected]", "[email protected]"], | ||
"name": "Lucas Cimon" | ||
}, | ||
"[email protected]": { | ||
"comment": " (luigibertaco)", | ||
"mails": ["[email protected]", "[email protected]"], | ||
|
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 |
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.