Add known problems warning to type-comparison rule (#12769)

## Summary

See: https://github.com/astral-sh/ruff/issues/4560
This commit is contained in:
Charlie Marsh 2024-08-08 21:41:15 -04:00 committed by GitHub
parent bc5b9b81dd
commit c906b0183b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,6 +18,22 @@ use crate::checkers::ast::Checker;
/// ///
/// If you want to check for an exact type match, use `is` or `is not`. /// 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 /// ## Example
/// ```python /// ```python
/// if type(obj) == type(1): /// if type(obj) == type(1):