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

Ignore pragma when considering E501 #3894

Closed
baggiponte opened this issue Apr 6, 2023 · 6 comments
Closed

Ignore pragma when considering E501 #3894

baggiponte opened this issue Apr 6, 2023 · 6 comments
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule

Comments

@baggiponte
Copy link
Contributor

I wrote this snippet of code and the <- ! line triggers E501.

def load_dynamodb(fileobj: IO | str | bytes | bytearray) -> dict[str, Any]:
    """Loads a dynamodb json fileobject."""
    if isinstance(fileobj, (str, bytes, bytearray)):
        return json.loads(fileobj, object_hook=_dynamo_hook)  # type: ignore [no-any-return] <- !
    return json.load(fileobj, object_hook=_dynamo_hook)  # type: ignore [no-any-return]

Since what triggers the warning is the pragma, I wanted to ask whether you believe that pragmas should not trigger E501 - something that Google has recently done with their pyink Python code formatter.

@charliermarsh charliermarsh added the question Asking for support or clarification label Apr 6, 2023
@charliermarsh
Copy link
Member

Yeah that's an interesting question. I tend to agree, but let me leave this open for a bit to see if any other opinions come in.

@bryanforbes
Copy link

flake8-bugbear recently changed B950 to ignore noqa and type: ignore comments when determining whether to report the error or not, so there's some precedence for ignoring pragmas

@charliermarsh
Copy link
Member

Oh that's great to know. Honestly that might be enough of a justification to just ship it :)

@baggiponte
Copy link
Contributor Author

I would also add to the ignore list black's "# fmt: {on,off,skip}" 🙏🏻

@bryanforbes
Copy link

What I'd love to see is a way to configure which pragmas that ruff ignores. For my use, I would want it to ignore # noqa: code, # type: ignore[code], and # pyright: ignore[code], but others have pragmas they also want supported. Making it configurable makes everyone happy and also preserves the current behavior when left unconfigured.

@charliermarsh charliermarsh added needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule and removed question Asking for support or clarification labels Jul 10, 2023
@charliermarsh
Copy link
Member

We made this change recently. It'll be out in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

3 participants