astral-sh/ruff

SIM114: Safe fix removes comments

Ouverte

#19 576 ouverte le 27 juil. 2025

 (8 commentaires) (2 réactions) (0 personne assignée)Rust (2 088 forks)batch import
bugfixeshelp wanted

Métriques du dépôt

Stars
 (47 527 étoiles)
Métriques de merge PR
 (Merge moyen 3j 8h) (573 PRs mergées en 30 j)

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

Guide contributeur