Skip to content

Commit a04f641

Browse files
[use-implicit-booleaness] Fix comparison to empty strings across the codebase (#7722)
As it will become a default check in #6870 it will be easier to review it if we separate the two
1 parent f262c43 commit a04f641

File tree

5 files changed

+11
-17
lines changed

5 files changed

+11
-17
lines changed

pylint/checkers/strings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def _check_new_format(self, node: nodes.Call, func: bases.BoundMethod) -> None:
494494

495495
check_args = False
496496
# Consider "{[0]} {[1]}" as num_args.
497-
num_args += sum(1 for field in named_fields if field == "")
497+
num_args += sum(1 for field in named_fields if not field)
498498
if named_fields:
499499
for field in named_fields:
500500
if field and field not in named_arguments:
@@ -509,7 +509,7 @@ def _check_new_format(self, node: nodes.Call, func: bases.BoundMethod) -> None:
509509
# num_args can be 0 if manual_pos is not.
510510
num_args = num_args or manual_pos
511511
if positional_arguments or num_args:
512-
empty = any(field == "" for field in named_fields)
512+
empty = not all(field for field in named_fields)
513513
if named_arguments or empty:
514514
# Verify the required number of positional arguments
515515
# only if the .format got at least one keyword argument.
@@ -546,7 +546,7 @@ def _check_new_format_specifiers(
546546
for key, specifiers in fields:
547547
# Obtain the argument. If it can't be obtained
548548
# or inferred, skip this check.
549-
if key == "":
549+
if not key:
550550
# {[0]} will have an unnamed argument, defaulting
551551
# to 0. It will not be present in `named`, so use the value
552552
# 0 for it.

pylint/config/_pylint_config/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def validate_yes_no(question: str, default: Literal["yes", "no"] | None) -> bool
8383
# pylint: disable-next=bad-builtin
8484
answer = input(question).lower()
8585

86-
if answer == "" and default:
86+
if not answer and default:
8787
answer = default
8888

8989
if answer not in YES_NO_ANSWERS:

pylint/testutils/_primer/primer_compare_command.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,14 @@ def _create_comment(
6363
comment += self._create_comment_for_package(
6464
package, new_messages, missing_messages
6565
)
66-
if comment == "":
67-
comment = (
66+
comment = (
67+
f"🤖 **Effect of this PR on checked open source code:** 🤖\n\n{comment}"
68+
if comment
69+
else (
6870
"🤖 According to the primer, this change has **no effect** on the"
6971
" checked open source code. 🤖🎉\n\n"
7072
)
71-
else:
72-
comment = (
73-
f"🤖 **Effect of this PR on checked open source code:** 🤖\n\n{comment}"
74-
)
73+
)
7574
return self._truncate_comment(comment)
7675

7776
def _create_comment_for_package(

pylint/testutils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def create_files(paths: list[str], chroot: str = ".") -> None:
9393
path = os.path.join(chroot, path)
9494
filename = os.path.basename(path)
9595
# path is a directory path
96-
if filename == "":
96+
if not filename:
9797
dirs.add(path)
9898
# path is a filename path
9999
else:

script/fix_documentation.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@ def changelog_insert_empty_lines(file_content: str, subtitle_text: str) -> str:
3636
for i, line in enumerate(lines):
3737
if line.startswith(subtitle_text):
3838
subtitle_count += 1
39-
if (
40-
subtitle_count == 1
41-
or i < 2
42-
or lines[i - 1] == ""
43-
and lines[i - 2] == ""
44-
):
39+
if subtitle_count == 1 or i < 2 or not lines[i - 1] and not lines[i - 2]:
4540
continue
4641
lines.insert(i, "")
4742
return "\n".join(lines)

0 commit comments

Comments
 (0)