Skip to content

ruff format moves # noqa comment to wrong location #10281

Closed
@jakob-keller

Description

@jakob-keller

I would like to switch my codebase to ruff format, but there is one annoying issue that breaks my use case: Some # noqa comments are moved resulting in issues when calling ruff check.

Hers's a minimal code snippet to demonstrate what happens:

# test.py (original)

import typing


def foo(
    __bar: str,
    /,
    **specifiers: typing.Any,  # noqa: ANN401
) -> int:
    return len(specifiers)
$ ruff --version
ruff 0.3.1

$ ruff check --isolated --select ANN401 test.py

$ ruff format --isolated test.py
1 file reformatted
# test.py (reformatted)

import typing


def foo(
    __bar: str,
    /,  # noqa: ANN401
    **specifiers: typing.Any,
) -> int:
    return len(specifiers)
$ ruff check --isolated --select ANN401 test.py
test.py:7:19: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**specifiers`
Found 1 error.

I assume this issue is an edge case that has to do with the keyword-only / syntax being used. Are there any workarounds available?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingformatterRelated to the formatter

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions