mirror of https://github.com/astral-sh/ruff
Pull in pycodestyle tests for E checks
This commit is contained in:
parent
d008a181ec
commit
de5bfdd662
|
|
@ -1,11 +1,50 @@
|
|||
if var == None:
|
||||
#: E711
|
||||
if res == None:
|
||||
pass
|
||||
#: E711
|
||||
if res != None:
|
||||
pass
|
||||
#: E711
|
||||
if None == res:
|
||||
pass
|
||||
#: E711
|
||||
if None != res:
|
||||
pass
|
||||
#: E711
|
||||
if res[1] == None:
|
||||
pass
|
||||
#: E711
|
||||
if res[1] != None:
|
||||
pass
|
||||
#: E711
|
||||
if None != res[1]:
|
||||
pass
|
||||
#: E711
|
||||
if None == res[1]:
|
||||
pass
|
||||
|
||||
if None != var:
|
||||
#: Okay
|
||||
if x not in y:
|
||||
pass
|
||||
|
||||
if var is None:
|
||||
if not (X in Y or X is Z):
|
||||
pass
|
||||
|
||||
if None is not var:
|
||||
if not (X in Y):
|
||||
pass
|
||||
|
||||
if x is not y:
|
||||
pass
|
||||
|
||||
if X is not Y is not Z:
|
||||
pass
|
||||
|
||||
if TrueElement.get_element(True) == TrueElement.get_element(False):
|
||||
pass
|
||||
|
||||
if (True) == TrueElement or x == TrueElement:
|
||||
pass
|
||||
|
||||
assert (not foo) in bar
|
||||
assert {"x": not foo} in bar
|
||||
assert [42, not foo] in bar
|
||||
|
|
|
|||
|
|
@ -1,14 +1,46 @@
|
|||
if var == True:
|
||||
#: E712
|
||||
if res == True:
|
||||
pass
|
||||
#: E712
|
||||
if res != False:
|
||||
pass
|
||||
#: E712
|
||||
if True != res:
|
||||
pass
|
||||
#: E712
|
||||
if False == res:
|
||||
pass
|
||||
#: E712
|
||||
if res[1] == True:
|
||||
pass
|
||||
#: E712
|
||||
if res[1] != False:
|
||||
pass
|
||||
#: E712
|
||||
var = 1 if cond == True else -1 if cond == False else cond
|
||||
#: E712
|
||||
if (True) == TrueElement or x == TrueElement:
|
||||
pass
|
||||
|
||||
if False != var:
|
||||
#: Okay
|
||||
if x not in y:
|
||||
pass
|
||||
|
||||
if var != False != True:
|
||||
if not (X in Y or X is Z):
|
||||
pass
|
||||
|
||||
if var is True:
|
||||
if not (X in Y):
|
||||
pass
|
||||
|
||||
if False is not var:
|
||||
if x is not y:
|
||||
pass
|
||||
|
||||
if X is not Y is not Z:
|
||||
pass
|
||||
|
||||
if TrueElement.get_element(True) == TrueElement.get_element(False):
|
||||
pass
|
||||
|
||||
assert (not foo) in bar
|
||||
assert {"x": not foo} in bar
|
||||
assert [42, not foo] in bar
|
||||
|
|
|
|||
|
|
@ -1,7 +1,38 @@
|
|||
my_list = [1, 2, 3]
|
||||
if not num in my_list:
|
||||
print(num)
|
||||
#: E713
|
||||
if not X in Y:
|
||||
pass
|
||||
#: E713
|
||||
if not X.B in Y:
|
||||
pass
|
||||
#: E713
|
||||
if not X in Y and Z == "zero":
|
||||
pass
|
||||
#: E713
|
||||
if X == "zero" or not Y in Z:
|
||||
pass
|
||||
#: E713
|
||||
if not (X in Y):
|
||||
pass
|
||||
|
||||
my_list = [1, 2, 3]
|
||||
if num not in my_list:
|
||||
print(num)
|
||||
#: Okay
|
||||
if x not in y:
|
||||
pass
|
||||
|
||||
if not (X in Y or X is Z):
|
||||
pass
|
||||
|
||||
if x is not y:
|
||||
pass
|
||||
|
||||
if X is not Y is not Z:
|
||||
pass
|
||||
|
||||
if TrueElement.get_element(True) == TrueElement.get_element(False):
|
||||
pass
|
||||
|
||||
if (True) == TrueElement or x == TrueElement:
|
||||
pass
|
||||
|
||||
assert (not foo) in bar
|
||||
assert {"x": not foo} in bar
|
||||
assert [42, not foo] in bar
|
||||
|
|
|
|||
|
|
@ -1,5 +1,38 @@
|
|||
if not user is None:
|
||||
print(user.name)
|
||||
#: E714
|
||||
if not X is Y:
|
||||
pass
|
||||
#: E714
|
||||
if not X.B is Y:
|
||||
pass
|
||||
#: E714
|
||||
if not X is Y is not Z:
|
||||
pass
|
||||
|
||||
if user is not None:
|
||||
print(user.name)
|
||||
#: Okay
|
||||
if not X is not Y:
|
||||
pass
|
||||
|
||||
if x not in y:
|
||||
pass
|
||||
|
||||
if not (X in Y or X is Z):
|
||||
pass
|
||||
|
||||
if not (X in Y):
|
||||
pass
|
||||
|
||||
if x is not y:
|
||||
pass
|
||||
|
||||
if X is not Y is not Z:
|
||||
pass
|
||||
|
||||
if TrueElement.get_element(True) == TrueElement.get_element(False):
|
||||
pass
|
||||
|
||||
if (True) == TrueElement or x == TrueElement:
|
||||
pass
|
||||
|
||||
assert (not foo) in bar
|
||||
assert {"x": not foo} in bar
|
||||
assert [42, not foo] in bar
|
||||
|
|
|
|||
|
|
@ -41,6 +41,14 @@ assert type(res) == type(())
|
|||
#: E201 E202 E721
|
||||
assert type(res) == type((0,))
|
||||
|
||||
assert type(res) == type(res)
|
||||
assert type(res) == type(int)
|
||||
assert type(res) == type()
|
||||
#: Okay
|
||||
import types
|
||||
|
||||
if isinstance(res, int):
|
||||
pass
|
||||
if isinstance(res, str):
|
||||
pass
|
||||
if isinstance(res, types.MethodType):
|
||||
pass
|
||||
if type(a) != type(b) or type(a) == type(ccc):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,9 +1,33 @@
|
|||
#: E722
|
||||
try:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
|
||||
#: E722
|
||||
try:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
#: E722
|
||||
try:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
#: Okay
|
||||
fake_code = """"
|
||||
try:
|
||||
do_something()
|
||||
except:
|
||||
pass
|
||||
"""
|
||||
try:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
#: Okay
|
||||
from . import compute_type
|
||||
|
||||
if compute_type(foo) == 5:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -1,6 +1,21 @@
|
|||
from typing import Callable, Iterable
|
||||
#: E731
|
||||
f = lambda x: 2 * x
|
||||
#: E731
|
||||
f = lambda x: 2 * x
|
||||
#: E731
|
||||
while False:
|
||||
this = lambda y, z: 2 * x
|
||||
|
||||
a = lambda x: x**2
|
||||
b = map(lambda x: 2 * x, range(3))
|
||||
c: Callable = lambda x: x**2
|
||||
d: Iterable = map(lambda x: 2 * x, range(3))
|
||||
|
||||
f = object()
|
||||
#: E731
|
||||
f.method = lambda: "Method"
|
||||
|
||||
f = {}
|
||||
#: E731
|
||||
f["a"] = lambda x: x ** 2
|
||||
|
||||
f = []
|
||||
f.append(lambda x: x ** 2)
|
||||
|
||||
lambda: "no-op"
|
||||
|
|
|
|||
|
|
@ -42,18 +42,20 @@ pub fn check_not_tests(
|
|||
|
||||
if matches!(op, Unaryop::Not) {
|
||||
if let ExprKind::Compare { ops, .. } = &operand.node {
|
||||
match ops[..] {
|
||||
[Cmpop::In] => {
|
||||
if check_not_in {
|
||||
checks.push(Check::new(CheckKind::NotInTest, operand.location));
|
||||
for op in ops {
|
||||
match op {
|
||||
Cmpop::In => {
|
||||
if check_not_in {
|
||||
checks.push(Check::new(CheckKind::NotInTest, operand.location));
|
||||
}
|
||||
}
|
||||
}
|
||||
[Cmpop::Is] => {
|
||||
if check_not_is {
|
||||
checks.push(Check::new(CheckKind::NotIsTest, operand.location));
|
||||
Cmpop::Is => {
|
||||
if check_not_is {
|
||||
checks.push(Check::new(CheckKind::NotIsTest, operand.location));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,13 +5,49 @@ expression: checks
|
|||
- kind:
|
||||
NoneComparison: Eq
|
||||
location:
|
||||
row: 1
|
||||
row: 2
|
||||
column: 11
|
||||
fix: ~
|
||||
- kind:
|
||||
NoneComparison: NotEq
|
||||
location:
|
||||
row: 4
|
||||
row: 5
|
||||
column: 11
|
||||
fix: ~
|
||||
- kind:
|
||||
NoneComparison: Eq
|
||||
location:
|
||||
row: 8
|
||||
column: 4
|
||||
fix: ~
|
||||
- kind:
|
||||
NoneComparison: NotEq
|
||||
location:
|
||||
row: 11
|
||||
column: 4
|
||||
fix: ~
|
||||
- kind:
|
||||
NoneComparison: Eq
|
||||
location:
|
||||
row: 14
|
||||
column: 14
|
||||
fix: ~
|
||||
- kind:
|
||||
NoneComparison: NotEq
|
||||
location:
|
||||
row: 17
|
||||
column: 14
|
||||
fix: ~
|
||||
- kind:
|
||||
NoneComparison: NotEq
|
||||
location:
|
||||
row: 20
|
||||
column: 4
|
||||
fix: ~
|
||||
- kind:
|
||||
NoneComparison: Eq
|
||||
location:
|
||||
row: 23
|
||||
column: 4
|
||||
fix: ~
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ expression: checks
|
|||
- true
|
||||
- Eq
|
||||
location:
|
||||
row: 1
|
||||
row: 2
|
||||
column: 11
|
||||
fix: ~
|
||||
- kind:
|
||||
|
|
@ -15,15 +15,7 @@ expression: checks
|
|||
- false
|
||||
- NotEq
|
||||
location:
|
||||
row: 4
|
||||
column: 4
|
||||
fix: ~
|
||||
- kind:
|
||||
TrueFalseComparison:
|
||||
- false
|
||||
- NotEq
|
||||
location:
|
||||
row: 7
|
||||
row: 5
|
||||
column: 11
|
||||
fix: ~
|
||||
- kind:
|
||||
|
|
@ -31,7 +23,55 @@ expression: checks
|
|||
- true
|
||||
- NotEq
|
||||
location:
|
||||
row: 7
|
||||
row: 8
|
||||
column: 4
|
||||
fix: ~
|
||||
- kind:
|
||||
TrueFalseComparison:
|
||||
- false
|
||||
- Eq
|
||||
location:
|
||||
row: 11
|
||||
column: 4
|
||||
fix: ~
|
||||
- kind:
|
||||
TrueFalseComparison:
|
||||
- true
|
||||
- Eq
|
||||
location:
|
||||
row: 14
|
||||
column: 14
|
||||
fix: ~
|
||||
- kind:
|
||||
TrueFalseComparison:
|
||||
- false
|
||||
- NotEq
|
||||
location:
|
||||
row: 17
|
||||
column: 14
|
||||
fix: ~
|
||||
- kind:
|
||||
TrueFalseComparison:
|
||||
- true
|
||||
- Eq
|
||||
location:
|
||||
row: 20
|
||||
column: 20
|
||||
fix: ~
|
||||
- kind:
|
||||
TrueFalseComparison:
|
||||
- false
|
||||
- Eq
|
||||
location:
|
||||
row: 20
|
||||
column: 44
|
||||
fix: ~
|
||||
- kind:
|
||||
TrueFalseComparison:
|
||||
- true
|
||||
- Eq
|
||||
location:
|
||||
row: 22
|
||||
column: 5
|
||||
fix: ~
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,26 @@ expression: checks
|
|||
- kind: NotInTest
|
||||
location:
|
||||
row: 2
|
||||
column: 10
|
||||
fix: ~
|
||||
- kind: NotInTest
|
||||
location:
|
||||
row: 5
|
||||
column: 12
|
||||
fix: ~
|
||||
- kind: NotInTest
|
||||
location:
|
||||
row: 8
|
||||
column: 10
|
||||
fix: ~
|
||||
- kind: NotInTest
|
||||
location:
|
||||
row: 11
|
||||
column: 25
|
||||
fix: ~
|
||||
- kind: NotInTest
|
||||
location:
|
||||
row: 14
|
||||
column: 11
|
||||
fix: ~
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,17 @@ expression: checks
|
|||
---
|
||||
- kind: NotIsTest
|
||||
location:
|
||||
row: 1
|
||||
column: 13
|
||||
row: 2
|
||||
column: 10
|
||||
fix: ~
|
||||
- kind: NotIsTest
|
||||
location:
|
||||
row: 5
|
||||
column: 12
|
||||
fix: ~
|
||||
- kind: NotIsTest
|
||||
location:
|
||||
row: 8
|
||||
column: 10
|
||||
fix: ~
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,17 @@ expression: checks
|
|||
---
|
||||
- kind: DoNotUseBareExcept
|
||||
location:
|
||||
row: 3
|
||||
row: 4
|
||||
column: 1
|
||||
fix: ~
|
||||
- kind: DoNotUseBareExcept
|
||||
location:
|
||||
row: 11
|
||||
column: 1
|
||||
fix: ~
|
||||
- kind: DoNotUseBareExcept
|
||||
location:
|
||||
row: 16
|
||||
column: 1
|
||||
fix: ~
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,27 @@ expression: checks
|
|||
---
|
||||
- kind: DoNotAssignLambda
|
||||
location:
|
||||
row: 3
|
||||
row: 2
|
||||
column: 1
|
||||
fix: ~
|
||||
- kind: DoNotAssignLambda
|
||||
location:
|
||||
row: 5
|
||||
row: 4
|
||||
column: 1
|
||||
fix: ~
|
||||
- kind: DoNotAssignLambda
|
||||
location:
|
||||
row: 7
|
||||
column: 5
|
||||
fix: ~
|
||||
- kind: DoNotAssignLambda
|
||||
location:
|
||||
row: 12
|
||||
column: 1
|
||||
fix: ~
|
||||
- kind: DoNotAssignLambda
|
||||
location:
|
||||
row: 16
|
||||
column: 1
|
||||
fix: ~
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue