-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flake8-pyi
] Mark fix as unsafe when type annotation contains comments for duplicate-literal-member
(PYI062
)
#14268
[flake8-pyi
] Mark fix as unsafe when type annotation contains comments for duplicate-literal-member
(PYI062
)
#14268
Conversation
…nts for `duplicate-literal-member` (`PYI062`)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs
Show resolved
Hide resolved
let fix = Fix::applicable_edit( | ||
Edit::range_replacement(checker.generator().expr(&subscript), expr.range()), | ||
if checker.comment_ranges().intersects(expr.range()) { | ||
Applicability::Unsafe | ||
} else { | ||
Applicability::Safe | ||
}, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. While I've never seen comments inside a Literal
annotation in "real life", this does seem to align with the rough consensus in #9790. So this change seems good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's very rare. My primary motivation for this type of changes is to give the right example for future uses. While developing new rules we often take existing rules as base, and being rigorous now might prevent issues in future rules where the comments do matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
|
Summary
Correctly mark fix as unsafe when comments are present within the annotation.
Test Plan
Added a test case