From b302d89da3325c705f87a8343a16aad1723b67ab Mon Sep 17 00:00:00 2001 From: Vasco Schiavo <115561717+VascoSch92@users.noreply.github.com> Date: Mon, 19 May 2025 22:38:08 +0200 Subject: [PATCH] [`flake8-simplify`] add fix safety section (`SIM110`) (#18114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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](https://github.com/astral-sh/ruff/blob/46be305ad243a5286d4269b1f8e5fd67623d38c2/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`? --- .../src/rules/flake8_simplify/rules/reimplemented_builtin.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs index c540628575..4530751a69 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs @@ -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)