Skip to content

Commit e5435eb

Browse files
authored
[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 ```
1 parent f53c580 commit e5435eb

File tree

1 file changed

+7
-0
lines changed
  • crates/ruff_linter/src/rules/flake8_simplify/rules

1 file changed

+7
-0
lines changed

crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ use crate::checkers::ast::Checker;
2727
/// bool(a)
2828
/// ```
2929
///
30+
/// ## Fix safety
31+
///
32+
/// This fix is marked as unsafe because it may change the program’s behavior if the condition does not
33+
/// return a proper Boolean. While the fix will try to wrap non-boolean values in a call to bool,
34+
/// custom implementations of comparison functions like `__eq__` can avoid the bool call and still
35+
/// lead to altered behavior. Moreover, the fix may remove comments.
36+
///
3037
/// ## References
3138
/// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing)
3239
#[derive(ViolationMetadata)]

0 commit comments

Comments
 (0)