Skip to content

Can't use other comments after "# fmt: ..." (like "# noqa: ...") #2213

@HarrySky

Description

@HarrySky

Describe the bug

Hi, I am experiencing an issue with # fmt: skip. If I put it next to long line - this line will be skipped (as expected):

log.debug("Long debug message ...........................................................")  # fmt: skip

But then flake8 will give me "E501 line too long" message, which I usually ignore with # noqa: E501 comment, but using it together with # fmt: skip is impossible, line below will be formatted:

log.debug("Long debug message, so we ignore flake8's E501 long line message")  # fmt: skip # noqa: E501

To Reproduce

  1. Create file test.py:
from logging import getLogger
log = getLogger("log")
log.debug("Long debug message, so we ignore flake8's E501 long line message")  # fmt: skip # noqa: E501
  1. Run Black on it
  2. See that line was not skipped, but formatted

Expected behavior

I expected black to handle it just as flake8 and bandit, they for example detect everything properly if I put both # nosec # noqa comments on the same line.

Environment:

  • Version: 21.5b0
  • OS and Python version: Ubuntu 18.04, Python 3.8.8

Does this bug also happen on main?

Yes, online formatter link

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: fmtskipfmt: skip implementationS: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedT: enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions