Skip to content

Warn on Unassigned == Expression as Statement #237

@pyflakes-bot

Description

@pyflakes-bot

Original report by scoutoss on Launchpad:


Working with some NumPy code recently, I accidentally wrote this:

<build output array>
<build mask array>

out[mask] == NaN  # This should have been a single `=`, not a ==.
return out

After a few minutes of debugging my NaN-less array, I realized that I had accidentally written == instead of =, turning my assignment statement into no-op comparison operator.

I'd be nice if PyFlakes gave a warning for a statement that's just an expression performing an equality comparison. There are very few cases where I'd expect that something like this is doing what the author intended.

A more aggressive version of this check would be to warn on any expression that's just a binary operator. The assumption there would be that the "statement" a + b is at best dead code, and at worst an operator with a highly non-obvious side-effect.

I'd be happy to work on either version of this if there's support for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions