Skip to content

Please don't break long lines if a '# type: ignore' takes it over the max length #997

@gvanrossum

Description

@gvanrossum

I am fixing a large number of mypy errors in a code base that is automatically Black-reformatted.

I keep running in the issue where I must add a # type: ignore to the end of some line, and that takes it over the max length. Black reformats the line, keeping the # type: ignore at the end of the statement, but the mypy error is specific to some subexpression that's not on the last line after reformatting.

For example,

            new_assocs = ViewNotificationRecipientAssoc.multiadd(assocs_to_add)  # type: ignore

is reformatted as

            new_assocs = ViewNotificationRecipientAssoc.multiadd(
                assocs_to_add
            )  # type: ignore

but actually the error happens on the first line, so I must manually change this to

            new_assocs = ViewNotificationRecipientAssoc.multiadd(    # type: ignore
                assocs_to_add
            )

(A similar thing happens to list literals and comprehensions.)

Can you please (even if only as an option) make it so that a # type: ignore comment is not considered to exceed the line length?

Note that for a regular type annotation (e.g. # type: List[int]) this is not a problem, so I'm fine with those being moved around. But # type: ignore is tied specifically to a line number.

I wouldn't bring this up if I didn't encounter this over and over.

CC: @msullivan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions