From c906b0183b5001e61c063f3122805d470c73331c Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 8 Aug 2024 21:41:15 -0400 Subject: [PATCH] Add known problems warning to `type-comparison` rule (#12769) ## Summary See: https://github.com/astral-sh/ruff/issues/4560 --- .../rules/pycodestyle/rules/type_comparison.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 ed9430b963..3adaef03ab 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/type_comparison.rs @@ -18,6 +18,22 @@ use crate::checkers::ast::Checker; /// /// If you want to check for an exact type match, use `is` or `is not`. /// +/// ## Known problems +/// When using libraries that override the `==` (`__eq__`) operator (such as NumPy, +/// Pandas, and SQLAlchemy), this rule may produce false positives, as converting +/// from `==` to `is` or `is not` will change the behavior of the code. +/// +/// For example, the following operations are _not_ equivalent: +/// ```python +/// import numpy as np +/// +/// np.array([True, False]) == False +/// # array([False, True]) +/// +/// np.array([True, False]) is False +/// # False +/// ``` +/// /// ## Example /// ```python /// if type(obj) == type(1):