-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Autofix for I001
unexpectedly altering characters from Unicode Block “Letterlike Symbols”
#10528
Comments
Thanks for the clear write-up! cc @AlexWaygood |
I can take if you're off for the day, Alex, up to you. |
Yes please, thanks! |
Thank you for the quick response, and for respecting work-life balance! Admittedly the affected users may be limited to physicists who spend too much of their time looking up Unicode tables, so it's not too urgent. Also I should clarify that |
No prob, I like fixing stuff like this. |
Is there a scientific repository we can add to the ecosystem checks that would catch this? |
## Summary Ensures that we use the raw identifier as provided in the source code, rather than the normalized Unicode identifier. This _does_ mean that we treat these as two separate identifiers, and _don't_ merge them, even though Python will treat them as the same symbol: ```python import numpy as ℂℇℊℋℌℍℎℐℑℒℓℕℤΩℨKÅℬℭℯℰℱℹℴ import numpy as CƐgHHHhIILlNZΩZKÅBCeEFio ``` I think that's fine, this is super rare anyway and would likely be confusing for users. Closes #10528. ## Test Plan `cargo test`
Thank you for the amazingly quick bugfix! I'm starting to understand better the difficulties of dealing with Unicode edge cases...
I found it in PlasmaPy in our notebook on Coulomb logarithms, using nbqa-ruff. |
With ruff 0.3.4, I ran into unexpected behavior where the autofix for ruff rule
I001
is now altering some characters from Unicode Block “Letterlike Symbols” (U+2100). I suspect that this is related to #10412. 🤔 This might not be the only Unicode block that is affected by this.For example,$2π$ ) is changed to
ℏ
(U+210F; which represents Planck's constant overħ
(U+0127; Latin Small Letter H with Stroke). To reproduce this, I created a file calledhbar.py
that contains:After I ran:
ruff check hbar.py --select=I001 --fix
I did a
git diff
and got this:Similarly, if I apply
I001
to a file containing a bunch of characters from that block:then the diff is
My expectation was for ruff to not change variable names that are valid Python names, except for rules that are designed specifically to make these changes (e.g.,
RUF001
,RUF002
,RUF003
).Thank you again for creating a wonderful tool!
The text was updated successfully, but these errors were encountered: