Document use of math.isnan for self-comparisons (#9033)

Closes https://github.com/astral-sh/ruff/issues/8833.
This commit is contained in:
Charlie Marsh
2023-12-06 21:33:38 -05:00
committed by GitHub
parent af88ffc57e
commit f484df5470

View File

@@ -21,6 +21,14 @@ use crate::rules::pylint::helpers::CmpOpExt;
/// foo == foo
/// ```
///
/// In some cases, self-comparisons are used to determine whether a float is
/// NaN. Instead, prefer `math.isnan`:
/// ```python
/// import math
///
/// math.isnan(foo)
/// ```
///
/// ## References
/// - [Python documentation: Comparisons](https://docs.python.org/3/reference/expressions.html#comparisons)
#[violation]