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

Allow f-strings with %z for DTZ007 #10651

Merged
merged 2 commits into from Mar 29, 2024
Merged

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Mar 29, 2024

Summary

This PR fixes the bug for DTZ007 rule where it didn't consider to check for the presence of %z in f-strings. It also considers the string parts of an implicitly concatenated f-strings for which I want to find a better solution (#10308).

fixes: #10601

Test Plan

Add test cases and update the snapshots.

@dhruvmanila dhruvmanila added the bug Something isn't working label Mar 29, 2024
Comment on lines 113 to 114
// TODO(dhruvmanila): This doesn't consider f-strings that are implicitly concatenated
// to strings. For example, `f"%Y-%m-%dT%H:%M:%S{('.%f' if millis else '')}" "%z"`
Copy link
Member

Choose a reason for hiding this comment

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

Should we check in a test case for this anyway?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ruff will raise a violation in this case even though it shouldn't. Maybe checking string literal isn't too bad 🤔

Copy link
Member

@zanieb zanieb Mar 29, 2024

Choose a reason for hiding this comment

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

I think it's fine to have an "incorrect" test case as long as it's clearly documented, then we have a test demonstrating the fix when you get to it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. I've added a commit which also checks for the implicitly concatenated case.

Copy link
Contributor

github-actions bot commented Mar 29, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dhruvmanila dhruvmanila merged commit 1bcdfe2 into main Mar 29, 2024
17 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/f-strings-for-DTZ007 branch March 29, 2024 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DTZ007 with F-string format specifier
2 participants