Skip to content

Autofix for I001 unexpectedly altering characters from Unicode Block “Letterlike Symbols” #10528

@namurphy

Description

@namurphy

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, (U+210F; which represents Planck's constant over $2π$) is changed to ħ (U+0127; Latin Small Letter H with Stroke). To reproduce this, I created a file called hbar.py that contains:

from astropy.constants import hbar as 
from numpy import pi as π

h = 2 * π * 

After I ran:

ruff check hbar.py  --select=I001 --fix

I did a git diff and got this:

@@ -1,4 +1,4 @@
-from astropy.constants import hbar as ℏ
+from astropy.constants import hbar as ħ
 from numpy import pi as π

Similarly, if I apply I001 to a file containing a bunch of characters from that block:

import numpy as ℂℇℊℋℌℍℎℐℑℒℓℕℤΩℨKÅℬℭℯℰℱℹℴ

then the diff is

@@ -1 +1 @@
-import numpy as ℂℇℊℋℌℍℎℐℑℒℓℕℤΩℨKÅℬℭℯℰℱℹℴ
+import numpy as CƐgHHHhIILlNZΩZKÅBCeEFio

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!

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions