mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
Add known problems warning to type-comparison
rule (#12769)
## Summary See: https://github.com/astral-sh/ruff/issues/4560
This commit is contained in:
parent
bc5b9b81dd
commit
c906b0183b
1 changed files with 16 additions and 0 deletions
|
@ -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):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue