Skip to content

Conversation

@danparizher
Copy link
Contributor

Summary

Fixes #19577

@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dylwil3 dylwil3 self-assigned this Jul 29, 2025
@MichaReiser MichaReiser requested a review from ntBre July 31, 2025 17:07
Copy link
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

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

This looks good, thank you! A couple of nits and then a design point:

I think we should gate this fix behavior under preview, and when not in preview just skip the check in this situation.

The reason is that it's unclear to me if the best thing to do here is to offer your fix (which would change part of a raw string into a string with escapes), to skip the check here, or to offer the fix with the "ugly" triple quotes for the relevant list items (or some compromise - like offer your fix but make it Unsafe). On the other hand, we have to do something to fix the syntax error, and I think this arrangements allows us to consider the other options in the meantime without making a breaking change.

(But I could be overruled on this)

@tdulcet
Copy link

tdulcet commented Aug 2, 2025

The reason is that it's unclear to me if the best thing to do here is to offer your fix (which would change part of a raw string into a string with escapes), to skip the check here, or to offer the fix with the "ugly" triple quotes for the relevant list items

At least in the example from #19577, there are no embedded single quote characters, so one should be able to cleanly convert it to a raw single quoted string without needing to add any additional escaping:

test_email_addresses = [
    r"[email protected]",
    r"[email protected]",
    r"[email protected]",
    r"[email protected]",
    r"[email protected]",
    r"[email protected]",
    r"name/[email protected]",
    r"[email protected]",
    r'" "@example.org',
    r'"john..doe"@example.org',
    r"[email protected]",
    r'"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com',
    r"user%[email protected]",
    r"[email protected]",
    r"I❤️[email protected]",
    r"this\ still\"not\\[email protected]",
    r"[email protected]",
    r"[email protected]",
    r"user+mailbox/[email protected]",
    r"!#$%&'*+-/=?^_`.{|}[email protected]",
    r'"Abc@def"@example.com',
    r'"Fred\ Bloggs"@example.com',
    r'"Joe.\\Blow"@example.com',
]

In (rare) cases where a triple quoted string does include both single and double quote characters, I would argue that the keeping the triple quotes for those items would be better than adding escaping, which would make the resulting items very difficult to read, especially if they already include backslash characters.

@dylwil3
Copy link
Collaborator

dylwil3 commented Aug 3, 2025

That's a good point @tdulcet , thank you! I think at that point it's maybe unobtrusive enough to fix the bug this way without gating behind preview. Let me know if the new snapshots look objectionable - otherwise I'll merge this in shortly

Copy link
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

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

Thanks @danparizher !

@dylwil3 dylwil3 added bug Something isn't working fixes Related to suggested fixes for violations labels Aug 3, 2025
@dylwil3 dylwil3 changed the title [flake8_simplify] Fix raw string handling in SIM905 for embedded quotes [flake8-simplify] Fix raw string handling in SIM905 for embedded quotes Aug 3, 2025
@dylwil3 dylwil3 merged commit 1a368b0 into astral-sh:main Aug 3, 2025
37 checks passed
@danparizher danparizher deleted the fix-19577 branch August 3, 2025 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Fix error] SIM905 (split-static-string) autofix does not work with embeded quotes

3 participants