negated-operator

not written before a membership or identity test.

Group
Code
Runs
On by default
Level
warning
Reads
Every file
Fix
--fix fixes it: puts the negation in the operator, which means the same

Why

not x in xs and not x is y negate a test that Python can state negated: x not in xs and x is not y mean the same and read in the order they are said. A test that is one link of a chain, such as not a in b in c, is a different test and is not reported.

The fix, as Ur suggests it: write not in or is not.

For agents

Write x not in xs and x is not y, never not x in xs or not x is y.

Example

app/access.py
def allowed(user, banned):
    return not user in banned
What Ur prints
$ ur lint --rule negated-operator
warning[negated-operator]: `not` before a membership test; write `not in`
  --> ./app/access.py:2:12 `not user in banned`
  = hint: write `not in` or `is not`; `--fix` does this
  = see: PEP 8 - Style Guide for Python Code, Programming Recommendations, Guido van Rossum, Barry Warsaw, and Alyssa Coghlan (2001-07-05), https://peps.python.org/pep-0008/#programming-recommendations
0 clone classes and 1 `negated-operator` finding in 1 file

Try it in the playground →

Source

PEP 8 - Style Guide for Python Code, Programming Recommendations, Guido van Rossum, Barry Warsaw, and Alyssa Coghlan (2001-07-05).