From 73317a1a95000be2c0aa56b03b1704e9d0a0d787 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 12 Jul 2024 08:32:29 -0400 Subject: [PATCH] Remove 'non-obvious' allowance for E721 --- .../src/rules/pycodestyle/rules/type_comparison.rs | 13 +------------ ...er__rules__pycodestyle__tests__E721_E721.py.snap | 10 ++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs index da713b11e924a2..34f413a94d9ccd 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs @@ -74,18 +74,7 @@ pub(crate) fn type_comparison(checker: &mut Checker, compare: &ast::ExprCompare) /// Returns `true` if the [`Expr`] is known to evaluate to a type (e.g., `int`, or `type(1)`). fn is_type(expr: &Expr, semantic: &SemanticModel) -> bool { match expr { - Expr::Call(ast::ExprCall { - func, arguments, .. - }) => { - // Allow comparison for types which are not obvious. - if !arguments - .args - .first() - .is_some_and(|arg| !arg.is_name_expr() && !arg.is_none_literal_expr()) - { - return false; - } - + Expr::Call(ast::ExprCall { func, .. }) => { // Ex) `type(obj) == type(1)` semantic.match_builtin_expr(func, "type") } diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E721_E721.py.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E721_E721.py.snap index 749cc427ed7acf..6d167b48019227 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E721_E721.py.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E721_E721.py.snap @@ -40,6 +40,16 @@ E721.py:21:8: E721 Use `is` and `is not` for type comparisons, or `isinstance()` 23 | assert type(res) == type([]) | +E721.py:21:36: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks + | +19 | pass +20 | #: E721 +21 | assert type(res) == type(False) or type(res) == type(None) + | ^^^^^^^^^^^^^^^^^^^^^^^ E721 +22 | #: E721 +23 | assert type(res) == type([]) + | + E721.py:23:8: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks | 21 | assert type(res) == type(False) or type(res) == type(None)