[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:
Vasco Schiavo 2025-05-19 22:38:08 +02:00 committed by GitHub
parent ce43dbab58
commit b302d89da3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)