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

formatter moves type:ignore comment and makes line too long #7730

Closed
DetachHead opened this issue Oct 1, 2023 · 3 comments
Closed

formatter moves type:ignore comment and makes line too long #7730

DetachHead opened this issue Oct 1, 2023 · 3 comments
Labels
formatter Related to the formatter

Comments

@DetachHead
Copy link

before

def run_pytest(pytester, subprocess):
    result = (
        pytester.runpytest_subprocess 
        if subprocess else pytester.runpytest  # type:ignore[no-any-expr]
    )(*(pytest_args or []))

after

def run_pytest(pytester, subprocess):
    result = (
        pytester.runpytest_subprocess if subprocess else pytester.runpytest  # type:ignore[no-any-expr]
    )(*(pytest_args or []))
E501 Line too long (103 > 100 characters)

playground

https://play.ruff.rs/720b0769-e4d7-430f-8e14-5c7295607d6d

@charliermarsh
Copy link
Member

This is an intentional behavior as we exclude pragmas when computing line length in the formatter: https://github.com/astral-sh/ruff/blob/main/crates/ruff_python_formatter/README.md#pragma-comments-are-ignored-when-computing-line-width.

In the next release, we're planning to ignore them when enforcing E501 violations to make the linter consistent with this behavior.

@charliermarsh
Copy link
Member

I'm gonna close as fixed by #7692, but won't actually be fixed until we cut the next release.

@jonyscathe
Copy link

This is an intentional behavior as we exclude pragmas when computing line length in the formatter: https://github.com/astral-sh/ruff/blob/main/crates/ruff_python_formatter/README.md#pragma-comments-are-ignored-when-computing-line-width.

The example given there says that "Ruff will also avoid moving pragma comments" essentially to avoid suppressing more errors than intended.
However in the example above Ruff not only exceeds the line length, but also applies the type ignore to more code than was originally intended (benign here, but could suppress genuine errors in some cases)

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

No branches or pull requests

3 participants