mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Add known problems to compare-to-empty-string
documentation (#5879)
## Summary Add known problems to `compare-to-empty-string` documentation. Related to #5873. Tweaked the example in the documentation to be a tad more concise and correct (that the rule is most applicable when comparing to a `str` variable). ## Test Plan `python scripts/check_docs_formatted.py`
This commit is contained in:
parent
9834c69c98
commit
23cde4d1f5
1 changed files with 14 additions and 6 deletions
|
@ -15,22 +15,30 @@ use crate::checkers::ast::Checker;
|
|||
/// the value can be something else Python considers falsy, such as `None` or
|
||||
/// `0` or another empty container, then the code is not equivalent.
|
||||
///
|
||||
/// ## Known problems
|
||||
/// High false positive rate, as the check is context-insensitive and does not
|
||||
/// consider the type of the variable being compared ([#4282]).
|
||||
///
|
||||
/// ## Example
|
||||
/// ```python
|
||||
/// def foo(x):
|
||||
/// if x == "":
|
||||
/// print("x is empty")
|
||||
/// x: str = ...
|
||||
///
|
||||
/// if x == "":
|
||||
/// print("x is empty")
|
||||
/// ```
|
||||
///
|
||||
/// Use instead:
|
||||
/// ```python
|
||||
/// def foo(x):
|
||||
/// if not x:
|
||||
/// print("x is empty")
|
||||
/// x: str = ...
|
||||
///
|
||||
/// if not x:
|
||||
/// print("x is empty")
|
||||
/// ```
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing)
|
||||
///
|
||||
/// [#4282]: https://github.com/astral-sh/ruff/issues/4282
|
||||
#[violation]
|
||||
pub struct CompareToEmptyString {
|
||||
existing: String,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue