mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
[flake8-simplify
] add fix safety section (SIM110
) (#18114)
The PR add the `fix safety` section for rule `SIM110` (#15584 )
### Unsafe Fix Example
```python
def predicate(item):
global called
called += 1
if called == 1:
# after first call we change the method
def new_predicate(_): return False
globals()['predicate'] = new_predicate
return True
def foo():
for item in range(10):
if predicate(item):
return True
return False
def foo_gen():
return any(predicate(item) for item in range(10))
called = 0
print(foo()) # true – returns immediately on first call
called = 0
print(foo_gen()) # false – second call uses new `predicate`
```
### Note
I notice that
[here](46be305ad2/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs (L60)
)
we have two rules, `SIM110` & `SIM111`. The second one seems not anymore
active. Should I delete `SIM111`?
This commit is contained in:
parent
ce43dbab58
commit
b302d89da3
1 changed files with 4 additions and 0 deletions
|
@ -34,6 +34,10 @@ use crate::line_width::LineWidthBuilder;
|
|||
/// return any(predicate(item) for item in iterable)
|
||||
/// ```
|
||||
///
|
||||
/// # Fix safety
|
||||
///
|
||||
/// This fix is always marked as unsafe because it might remove comments.
|
||||
///
|
||||
/// ## References
|
||||
/// - [Python documentation: `any`](https://docs.python.org/3/library/functions.html#any)
|
||||
/// - [Python documentation: `all`](https://docs.python.org/3/library/functions.html#all)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue