Skip to content

[flake8-pyi] Mark fix as unsafe when type annotation contains comments for duplicate-literal-member (PYI062)#14268

Merged
AlexWaygood merged 1 commit intoastral-sh:mainfrom
sbrugman:pyi062-applicability-comments
Nov 11, 2024
Merged

[flake8-pyi] Mark fix as unsafe when type annotation contains comments for duplicate-literal-member (PYI062)#14268
AlexWaygood merged 1 commit intoastral-sh:mainfrom
sbrugman:pyi062-applicability-comments

Conversation

@sbrugman
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense.

@github-actions
Copy link
Copy Markdown
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
@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