Don't trigger E721 when comparing with None (#1356)
This commit is contained in:
4
resources/test/fixtures/pycodestyle/E721.py
vendored
4
resources/test/fixtures/pycodestyle/E721.py
vendored
@@ -15,7 +15,7 @@ import types
|
||||
if type(res) is not types.ListType:
|
||||
pass
|
||||
#: E721
|
||||
assert type(res) == type(False) or type(res) == type(None)
|
||||
assert type(res) == type(False)
|
||||
#: E721
|
||||
assert type(res) == type([])
|
||||
#: E721
|
||||
@@ -52,3 +52,5 @@ if isinstance(res, types.MethodType):
|
||||
pass
|
||||
if type(a) != type(b) or type(a) == type(ccc):
|
||||
pass
|
||||
|
||||
assert type(res) == type(None)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use itertools::izip;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use rustpython_ast::{Located, Location, Stmt, StmtKind};
|
||||
use rustpython_ast::{Constant, Located, Location, Stmt, StmtKind};
|
||||
use rustpython_parser::ast::{Cmpop, Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
@@ -55,7 +55,14 @@ pub fn type_comparison(ops: &[Cmpop], comparators: &[Expr], location: Range) ->
|
||||
if id == "type" {
|
||||
if let Some(arg) = args.first() {
|
||||
// Allow comparison for types which are not obvious.
|
||||
if !matches!(arg.node, ExprKind::Name { .. }) {
|
||||
if !matches!(
|
||||
arg.node,
|
||||
ExprKind::Name { .. }
|
||||
| ExprKind::Constant {
|
||||
value: Constant::None,
|
||||
kind: None
|
||||
}
|
||||
) {
|
||||
checks.push(Check::new(CheckKind::TypeComparison, location));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,14 +42,6 @@ expression: checks
|
||||
row: 18
|
||||
column: 31
|
||||
fix: ~
|
||||
- kind: TypeComparison
|
||||
location:
|
||||
row: 18
|
||||
column: 35
|
||||
end_location:
|
||||
row: 18
|
||||
column: 58
|
||||
fix: ~
|
||||
- kind: TypeComparison
|
||||
location:
|
||||
row: 20
|
||||
|
||||
Reference in New Issue
Block a user