diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2023-04-26 21:50:45 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2023-05-02 20:01:39 +0200 |
commit | 918f4624d76197bec7cc54467f0281ff63c19c5a (patch) | |
tree | 1a7ca06809bff250669d6ca7faa04ab30acd0668 /doc | |
parent | 26686d544eab7236a92e56cc90c34b6e3a37f473 (diff) | |
download | pylint-git-918f4624d76197bec7cc54467f0281ff63c19c5a.tar.gz |
Merge the empty-string extensions to 'implicit_booleaness_checker'
Diffstat (limited to 'doc')
12 files changed, 29 insertions, 40 deletions
diff --git a/doc/data/messages/c/compare-to-empty-string/bad.py b/doc/data/messages/c/compare-to-empty-string/bad.py deleted file mode 100644 index 1ab940de7..000000000 --- a/doc/data/messages/c/compare-to-empty-string/bad.py +++ /dev/null @@ -1,8 +0,0 @@ -x = "" -y = "hello" - -if x == "": # [compare-to-empty-string] - print("x is an empty string") - -if y != "": # [compare-to-empty-string] - print("y is not an empty string") diff --git a/doc/data/messages/c/compare-to-empty-string/good.py b/doc/data/messages/c/compare-to-empty-string/good.py deleted file mode 100644 index 6c4c67e36..000000000 --- a/doc/data/messages/c/compare-to-empty-string/good.py +++ /dev/null @@ -1,8 +0,0 @@ -x = "" -y = "hello" - -if not x: - print("x is an empty string") - -if y: - print("y is not an empty string") diff --git a/doc/data/messages/c/compare-to-empty-string/pylintrc b/doc/data/messages/c/compare-to-empty-string/pylintrc deleted file mode 100644 index 13b9afd7e..000000000 --- a/doc/data/messages/c/compare-to-empty-string/pylintrc +++ /dev/null @@ -1,2 +0,0 @@ -[main] -load-plugins=pylint.extensions.emptystring diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/bad.py b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/bad.py new file mode 100644 index 000000000..119fd8b43 --- /dev/null +++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/bad.py @@ -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") diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/details.rst b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/details.rst new file mode 100644 index 000000000..257fb92bc --- /dev/null +++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/details.rst @@ -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. diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/good.py b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/good.py new file mode 100644 index 000000000..21f222e9b --- /dev/null +++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/good.py @@ -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") diff --git a/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/pylintrc b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/pylintrc new file mode 100644 index 000000000..aa53d9346 --- /dev/null +++ b/doc/data/messages/u/use-implicit-booleaness-not-comparison-to-string/pylintrc @@ -0,0 +1,2 @@ +[main] +enable=use-implicit-booleaness-not-comparison-to-string diff --git a/doc/user_guide/checkers/extensions.rst b/doc/user_guide/checkers/extensions.rst index f3823d715..79a797a7c 100644 --- a/doc/user_guide/checkers/extensions.rst +++ b/doc/user_guide/checkers/extensions.rst @@ -19,7 +19,6 @@ Pylint provides the following optional plugins: - :ref:`pylint.extensions.docstyle` - :ref:`pylint.extensions.dunder` - :ref:`pylint.extensions.empty_comment` -- :ref:`pylint.extensions.emptystring` - :ref:`pylint.extensions.eq_without_hash` - :ref:`pylint.extensions.for_any_all` - :ref:`pylint.extensions.magic_value` @@ -87,20 +86,6 @@ Code Style checker Messages to. This can be changed to be an augmented assign. Disabled by default! -.. _pylint.extensions.emptystring: - -Compare-To-Empty-String checker -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -This checker is provided by ``pylint.extensions.emptystring``. -Verbatim name of the checker is ``compare-to-empty-string``. - -Compare-To-Empty-String checker Messages -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -:compare-to-empty-string (C1901): *"%s" can be simplified to "%s" as an empty string is falsey* - Used when Pylint detects comparison to an empty string constant. - - .. _pylint.extensions.comparison_placement: Comparison-Placement checker diff --git a/doc/user_guide/checkers/features.rst b/doc/user_guide/checkers/features.rst index e30aff544..789d59b8b 100644 --- a/doc/user_guide/checkers/features.rst +++ b/doc/user_guide/checkers/features.rst @@ -893,8 +893,10 @@ Refactoring checker Messages Emitted when a single "return" or "return None" statement is found at the end of function or method definition. This statement can safely be removed because Python will implicitly return None -:use-implicit-booleaness-not-comparison-to-zero (C1804): *"%s" can be simplified to "%s" as 0 is falsey* +:use-implicit-booleaness-not-comparison-to-zero (C1805): *"%s" can be simplified to "%s" as 0 is falsey* Used when Pylint detects comparison to a 0 constant. +:use-implicit-booleaness-not-comparison-to-string (C1804): *"%s" can be simplified to "%s" as an empty string is falsey* + Used when Pylint detects comparison to an empty string constant. :use-implicit-booleaness-not-comparison (C1803): *'%s' can be simplified to '%s' as an empty %s is falsey* Used when Pylint detects that collection literal comparison is being used to check for emptiness; Use implicit booleaness instead of a collection classes; diff --git a/doc/user_guide/configuration/all-options.rst b/doc/user_guide/configuration/all-options.rst index 8ddafa104..8b68ab7dd 100644 --- a/doc/user_guide/configuration/all-options.rst +++ b/doc/user_guide/configuration/all-options.rst @@ -233,7 +233,7 @@ Standard Checkers confidence = ["HIGH", "CONTROL_FLOW", "INFERENCE", "INFERENCE_FAILURE", "UNDEFINED"] - disable = ["raw-checker-failed", "bad-inline-option", "locally-disabled", "file-ignored", "suppressed-message", "useless-suppression", "deprecated-pragma", "use-implicit-booleaness-not-comparison-to-zero", "use-symbolic-message-instead", "consider-using-augmented-assign"] + disable = ["raw-checker-failed", "bad-inline-option", "locally-disabled", "file-ignored", "suppressed-message", "useless-suppression", "deprecated-pragma", "use-implicit-booleaness-not-comparison-to-string", "use-implicit-booleaness-not-comparison-to-zero", "use-symbolic-message-instead", "consider-using-augmented-assign"] enable = [] diff --git a/doc/user_guide/messages/messages_overview.rst b/doc/user_guide/messages/messages_overview.rst index 50f77d35e..9515fecb4 100644 --- a/doc/user_guide/messages/messages_overview.rst +++ b/doc/user_guide/messages/messages_overview.rst @@ -390,7 +390,6 @@ All messages in the convention category: convention/bad-file-encoding convention/bad-mcs-classmethod-argument convention/bad-mcs-method-argument - convention/compare-to-empty-string convention/consider-iterating-dictionary convention/consider-using-any-or-all convention/consider-using-dict-items @@ -432,6 +431,7 @@ All messages in the convention category: convention/unnecessary-lambda-assignment convention/unneeded-not convention/use-implicit-booleaness-not-comparison + convention/use-implicit-booleaness-not-comparison-to-string convention/use-implicit-booleaness-not-comparison-to-zero convention/use-implicit-booleaness-not-len convention/use-maxsplit-arg @@ -449,6 +449,7 @@ All renamed messages in the convention category: :titlesonly: convention/blacklisted-name + convention/compare-to-empty-string convention/compare-to-zero convention/len-as-condition convention/missing-docstring diff --git a/doc/whatsnew/fragments/6871.user_action b/doc/whatsnew/fragments/6871.user_action index 9aceab4c1..e20983171 100644 --- a/doc/whatsnew/fragments/6871.user_action +++ b/doc/whatsnew/fragments/6871.user_action @@ -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 |