Skip to content

False negative 'for-any-all' when there is a break or a pre-initialized boolean #7699

Closed
@Pierre-Sassoulas

Description

@Pierre-Sassoulas

Current problem

def optimized_any_with_break(split_lines: list[str], max_chars: int) -> bool:
    """False negative found in https://github.com/PyCQA/pylint/pull/7697"""
    potential_line_length_warning = False
    for line in split_lines:  # [consider-using-any-or-all]
        if len(line) > max_chars:
            potential_line_length_warning = True
            break
    return potential_line_length_warning

Can be simplified to

def optimized_any_with_break(split_lines: list[str], max_chars: int) -> bool:
    return any(len(line) > max_chars for line in split_lines)

Desired solution

for-any-all raised in this case.

Additional context

I did not think very hard about potential false positive, but I think it make sense to not raise if potential_line_length_warning is not initialized directly above the for loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Negative 🦋No message is emitted but something is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions