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

Ruff treats every Chinese character as two and often falsely reports the "Line too long (E501)" warning #5133

Closed
jackjyq opened this issue Jun 16, 2023 · 2 comments

Comments

@jackjyq
Copy link

jackjyq commented Jun 16, 2023

I have noticed that Ruff treats every Chinese character as two, so it often falsely reports the "Line too long (E501)" warning.

x = "一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十"

I believe that this behavior is different than Flake8 and Black as they treat one Chinese character as one.

image

I use Ruff (v2023.20.0) the VSCode version with all the default settings.

Other considerations

I know that Chinese characters take more space than ASCII characters and the actual ratio depends on fonts and rendering.

On Windows 11 VSCode,

  • Dejavu Sans Mono: 53 Chinese characters take 88 ASCII characters' space
  • Cascadia Mono: 52 Chinese characters take 88 ASCII characters' space

As we can see, the radio is not 2.

Also, this behaviour makes Ruff not compatible with the Black formatter because more often than not, the Black does not break lines while Ruff keeps reporting the E501 warning.

@charliermarsh
Copy link
Member

There's a bit more info on this in #3902 and #3825. Ruff is using character width (which is defined as part of the Unicode standard, I think, although I'm not an expert), rather than character count. Black made the same change, but it's still in preview (you should see the same behavior if you run with black --preview). We may consider changing this, though I'm going to close this as a duplicate of the others for now.

@charliermarsh charliermarsh closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2023
@charliermarsh
Copy link
Member

(For posterity: the primary issue for tracking this is #3825.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants