Skip to content

[flake8-simplify] SIM910/SIM911 can delete comments #18775

@MeGaGiGaGon

Description

@MeGaGiGaGon

Summary

The fix for SIM910 will delete comments inside the get. If there are comments, they should be moved, the fix should be marked unsafe, or the fix should not apply. playground

PS ~\Desktop\New_folder>Get-Content issue.py
ages = {"Tom": 23, "Maria": 23, "Dog": 11}
age = ages.get( #1
"Cat" #2
, #3
None #4
# 5
)
PS ~\Desktop\New_folder>uvx ruff check issue.py --isolated --select SIM --fix --diff
--- issue.py
+++ issue.py
@@ -1,7 +1,2 @@
 ages = {"Tom": 23, "Maria": 23, "Dog": 11}
-age = ages.get( #1
-"Cat" #2
-, #3
-None #4
-# 5
-)
+age = ages.get("Cat")

Would fix 1 error.

This also applies to SIM911 playground

Version

ruff 0.12.0 (87f0feb 2025-06-17) + playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions