mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:47 +00:00
[flake8-simplify
] add fix safety section (SIM210
) (#18100)
The PR add the `fix safety` section for rule `SIM210` (#15584 ) It is a little cheating, as the Fix safety section is copy/pasted by #18086 as the problem is the same. ### Unsafe Fix Example ```python class Foo(): def __eq__(self, other): return 0 def foo(): return True if Foo() == 0 else False def foo_fix(): return Foo() == 0 print(foo()) # False print(foo_fix()) # 0 ```
This commit is contained in:
parent
f53c580c53
commit
e5435eb106
1 changed files with 7 additions and 0 deletions
|
@ -27,6 +27,13 @@ use crate::checkers::ast::Checker;
|
||||||
/// bool(a)
|
/// bool(a)
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// ## Fix safety
|
||||||
|
///
|
||||||
|
/// This fix is marked as unsafe because it may change the program’s behavior if the condition does not
|
||||||
|
/// return a proper Boolean. While the fix will try to wrap non-boolean values in a call to bool,
|
||||||
|
/// custom implementations of comparison functions like `__eq__` can avoid the bool call and still
|
||||||
|
/// lead to altered behavior. Moreover, the fix may remove comments.
|
||||||
|
///
|
||||||
/// ## References
|
/// ## References
|
||||||
/// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing)
|
/// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing)
|
||||||
#[derive(ViolationMetadata)]
|
#[derive(ViolationMetadata)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue