Skip to content
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

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

sbrugman
Copy link
Contributor

Summary

Correctly mark fix as unsafe when comments are present within the annotation.

Test Plan

Added a test case

…nts for `duplicate-literal-member` (`PYI062`)
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +99 to +106
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
},
);
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense.

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@AlexWaygood AlexWaygood added fixes Related to suggested fixes for violations rule Implementing or modifying a lint rule labels Nov 11, 2024
@AlexWaygood AlexWaygood merged commit f8aae9b into astral-sh:main Nov 11, 2024
20 checks passed
@sbrugman sbrugman deleted the pyi062-applicability-comments branch November 11, 2024 12:51
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 rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants