Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[flake8-simplify] Mark SIM910/SIM911 fix as unsafe when deleting comments#22600

Closed
eureka928 wants to merge 2 commits intoastral-sh:mainfrom
eureka928:18775_sim910_sim911_unsafe_fix_comments
Closed

[flake8-simplify] Mark SIM910/SIM911 fix as unsafe when deleting comments#22600
eureka928 wants to merge 2 commits intoastral-sh:mainfrom
eureka928:18775_sim910_sim911_unsafe_fix_comments

Conversation

@eureka928
Copy link

Summary

Fixes #18775

The SIM910 (dict-get-with-none-default) and SIM911 (zip-dict-keys-and-values) rules were silently deleting comments when applying fixes.

For example, SIM910 would transform:

ages = {"Tom": 23, "Maria": 23, "Dog": 11}
age = ages.get(  # comment
    "Cat", None
)
...

into:

```python
for k, v in d.items():
    ...

This fix marks such transformations as unsafe when comments would be deleted, requiring users to explicitly opt-in with --unsafe-fixes.

Approach

Uses the established CommentRanges::intersects() pattern already used by other rules in the codebase (as suggested by @MichaReiser in the issue). When comments exist within the expression's range, the fix is marked as Applicability::Unsafe instead of Applicability::Safe.

Test Plan

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=42954461

@eureka928
Copy link
Author

@BurntSushi @MichaReiser would you approve testing and review this PR?
Thank you for your time

@MichaReiser
Copy link
Member

Thanks for your PR

@BurntSushi @MichaReiser would you approve testing and review this PR? Thank you for your time

Please give us some time before pinging maintainers. We already get a lot of notifications and more notifications doesn't help us to get things done faster. BurntSushi also doesn't work at this part of the code base at all.

@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 15, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@eureka928
Copy link
Author

All testing passed!

@eureka928 eureka928 changed the title [flake8-simplify] Mark SIM910/SIM911 fix as unsafe when deleting comm… [flake8-simplify] Mark SIM910/SIM911 fix as unsafe when deleting comments Jan 15, 2026
@ntBre ntBre added the fixes Related to suggested fixes for violations label Jan 15, 2026
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This looks great, we just need to update the rule docs to reflect the new unsafety.

@eureka928 eureka928 force-pushed the 18775_sim910_sim911_unsafe_fix_comments branch from 0974249 to 2f6ca10 Compare January 19, 2026 18:02
@eureka928
Copy link
Author

Ready for review

@eureka928 eureka928 requested a review from ntBre January 19, 2026 18:02
@amyreese amyreese changed the title [flake8-simplify] Mark SIM910/SIM911 fix as unsafe when deleting comments [flake8-simplify] Mark SIM910/SIM911 fix as unsafe when deleting comments Jan 19, 2026
@eureka928 eureka928 force-pushed the 18775_sim910_sim911_unsafe_fix_comments branch from 2f6ca10 to 912b0d2 Compare January 21, 2026 12:20
@eureka928
Copy link
Author

@amyreese @ntBre would you review this PR again? I fixed the conflict and make this up-to-date

Copy link
Member

@amyreese amyreese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the pr_summary markdown files.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@eureka928 eureka928 requested a review from amyreese January 21, 2026 17:30
@eureka928
Copy link
Author

Please remove the pr_summary markdown files.

Updated! it was mistake

@ntBre
Copy link
Contributor

ntBre commented Jan 21, 2026

Sorry for the confusion! I didn't realize that #22661 and #22662 were fixing the same issue. I'll close this for now since the main changes have already been made. Thank you for working on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flake8-simplify] SIM910/SIM911 can delete comments

4 participants