-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
RUF002 offers unrelated substitution for unicode quotation mark #3977
Comments
Hm, yeah, that's an interesting substitution. We actually didn't create the substitution table -- it's taken from the same source as VS Code, and is intended to match VS Code's own list of confusing characters + their replacements. It looks like VS Code offers the same suggestion: That's not to say that the table can't be improved, only to clarify that we didn't apply any of our own discretion in generating the list. We could consider changing that replacement to instead suggest |
'All the account’s items.' works as a docstring, although a dodgy one... Substituting |
I would make 2 suggestions for this issue:
or,
For # 2, would it be possible to construct an anti-example where this suggestion could still change the meaning of code? For example, constructing a string and passing it to eval? |
I think auto fix should probably be disabled for this sort of thing since the underlying ambiguous characters might be in a i18n related string or some documentation (even if it's not a doc comment, e.g., Django column help text) that is intentional |
Does anyone here see If not: why is On a different note, it hurts my typographic sensibilities to see that specific substitution being made lol. I always see when people using grave accents instead of typographically correct quotes, and I always wince. |
What is being replaced originally comes from Unicode directly, with only some minor overrides from vscode. That a grave accent is recommended here is an upstream bug imho. My PR contains some background information as well: hediet/vscode-unicode-data#1 The discussion whether replacing with [tool.ruff]
allowed-confusables = [
"’", # Cf. https://github.com/astral-sh/ruff/issues/3977
] |
I have a similar problem. I get Couldn't be sure if I should open a new issue. Please let me know if so. |
@kureta - I think that's following the intent of the rule, since the goal is to identify confusable Unicode characters in otherwise-ASCII words. I'd suggest adding it to the |
@charliermarsh thanks, i didn't know that option. |
With ruff 0.0.261, using the "RUF" rule, the following docstring:
"""All the account’s items"""
produces the following error:
The Unicode character in the comment is U+2019 RIGHT SINGLE QUOTATION MARK which is drawn from upper right to lower left. The suggested substitution is the backtick character which is drawn from upper left to lower right - this character is not semantically related to the Unicode character.
This suggestion is automatically applied when
--fix
is specified, producing:"""All the account`s items"""
Is this to avoid messing with docstring quotes by not substituting the single quote character
'
? In that case I would suggest not making this Unicode character autofixable at all, rather than substituting an unrelated character.The text was updated successfully, but these errors were encountered: