astral-sh/ruff

SIM114: Safe fix removes comments

Open

#19,576 opened on Jul 27, 2025

View on GitHub
 (8 comments) (2 reactions) (0 assignees)Rust (2,088 forks)batch import
bugfixeshelp wanted

Repository metrics

Stars
 (47,527 stars)
PR merge metrics
 (Avg merge 5d 4h) (463 merged PRs in 30d)

Description

Summary

Example:

ruff check src/s3ql/backends/b2/b2_backend.py 
src/s3ql/backends/b2/b2_backend.py:362:9: SIM114 [*] Combine `if` branches using logical `or` operator
    |
360 |               return True
361 |
362 | /         elif isinstance(exc, HTTPError) and (
363 | |             (500 <= exc.status <= 599)
364 | |             or exc.status == 408  # server errors
365 | |             or exc.status == 429  # request timeout
366 | |         ):  # too many requests
367 | |             return True
368 | |
369 | |         # Consider all SSL errors as temporary. There are a lot of bug
370 | |         # reports from people where various SSL errors cause a crash
371 | |         # but are actually just temporary. On the other hand, we have
372 | |         # no information if this ever revealed a problem where retrying
373 | |         # was not the right choice.
374 | |         elif isinstance(exc, ssl.SSLError):
375 | |             return True
    | |_______________________^ SIM114
376 |
377 |           return False
    |
    = help: Combine `if` branches
[...]
Found 7 errors.
[*] 1 fixable with the `--fix` option (2 hidden fixes can be enabled with the `--unsafe-fixes` option).

I noticed that there's at least one older report about a similar problem with another rule. Perhaps there's a need for some generic safeguard that prevents removal of comments for any rule?

Version

ruff 0.12.5

Contributor guide