Skip to content

[use-implicit-booleaness] Fix comparison to empty strings across the codebase #7722

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pylint/checkers/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def _check_new_format(self, node: nodes.Call, func: bases.BoundMethod) -> None:

check_args = False
# Consider "{[0]} {[1]}" as num_args.
num_args += sum(1 for field in named_fields if field == "")
num_args += sum(1 for field in named_fields if not field)
if named_fields:
for field in named_fields:
if field and field not in named_arguments:
Expand All @@ -509,7 +509,7 @@ def _check_new_format(self, node: nodes.Call, func: bases.BoundMethod) -> None:
# num_args can be 0 if manual_pos is not.
num_args = num_args or manual_pos
if positional_arguments or num_args:
empty = any(field == "" for field in named_fields)
empty = not all(field for field in named_fields)
if named_arguments or empty:
# Verify the required number of positional arguments
# only if the .format got at least one keyword argument.
Expand Down Expand Up @@ -546,7 +546,7 @@ def _check_new_format_specifiers(
for key, specifiers in fields:
# Obtain the argument. If it can't be obtained
# or inferred, skip this check.
if key == "":
if not key:
# {[0]} will have an unnamed argument, defaulting
# to 0. It will not be present in `named`, so use the value
# 0 for it.
Expand Down
2 changes: 1 addition & 1 deletion pylint/config/_pylint_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def validate_yes_no(question: str, default: Literal["yes", "no"] | None) -> bool
# pylint: disable-next=bad-builtin
answer = input(question).lower()

if answer == "" and default:
if not answer and default:
answer = default

if answer not in YES_NO_ANSWERS:
Expand Down
11 changes: 5 additions & 6 deletions pylint/testutils/_primer/primer_compare_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ def _create_comment(
comment += self._create_comment_for_package(
package, new_messages, missing_messages
)
if comment == "":
comment = (
comment = (
f"🤖 **Effect of this PR on checked open source code:** 🤖\n\n{comment}"
if comment
else (
"🤖 According to the primer, this change has **no effect** on the"
" checked open source code. 🤖🎉\n\n"
)
else:
comment = (
f"🤖 **Effect of this PR on checked open source code:** 🤖\n\n{comment}"
)
)
return self._truncate_comment(comment)

def _create_comment_for_package(
Expand Down
2 changes: 1 addition & 1 deletion pylint/testutils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def create_files(paths: list[str], chroot: str = ".") -> None:
path = os.path.join(chroot, path)
filename = os.path.basename(path)
# path is a directory path
if filename == "":
if not filename:
dirs.add(path)
# path is a filename path
else:
Expand Down
7 changes: 1 addition & 6 deletions script/fix_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ def changelog_insert_empty_lines(file_content: str, subtitle_text: str) -> str:
for i, line in enumerate(lines):
if line.startswith(subtitle_text):
subtitle_count += 1
if (
subtitle_count == 1
or i < 2
or lines[i - 1] == ""
and lines[i - 2] == ""
):
if subtitle_count == 1 or i < 2 or not lines[i - 1] and not lines[i - 2]:
continue
lines.insert(i, "")
return "\n".join(lines)
Expand Down