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

[pyupgrade] Do not report when a UTF-8 comment is followed by a non-UTF-8 one (UP009) #14728

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

InSyncWithFoo
Copy link
Contributor

Summary

Resolves #14704.

Test Plan

cargo nextest run and cargo insta test.

Copy link
Contributor

github-actions bot commented Dec 2, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

diagnostics.push(diagnostic);
[Some(CodingComment::UTF8(ranges_1)), Some(CodingComment::UTF8(ranges_2))] => {
report(diagnostics, ranges_1.line_range, ranges_1.self_range);
report(diagnostics, ranges_2.line_range, ranges_2.self_range);
Copy link

@dscorbett dscorbett Dec 2, 2024

Choose a reason for hiding this comment

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

If this block removes both UTF-8 encoding declarations, what happens if there is a third, non-UTF-8 encoding declaration?

# coding=utf-8
# coding=utf-8
# coding=ascii

I think it would be better to only offer the fix for ranges_1. If it is safe to delete ranges_2 too, that can happen on the next iteration.

Copy link
Contributor Author

@InSyncWithFoo InSyncWithFoo Dec 2, 2024

Choose a reason for hiding this comment

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

Just to be clear, should we:

  • Report both but only suggest a fix for the first?
  • Report only the first?
  • Report both, marking the first fix safe but the second fix unsafe?
  • Another way?

Currently this rule is marked as always fixable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UP009 fix changes a file from UTF-8 to a different declared encoding
2 participants