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

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

Closed
HarrySky opened this issue May 10, 2021 · 10 comments
Closed

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

HarrySky opened this issue May 10, 2021 · 10 comments
Labels
F: fmtskip fmt: skip implementation S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: enhancement New feature or request

Comments

@HarrySky
Copy link

HarrySky commented May 10, 2021

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

@ichard26 ichard26 added S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: enhancement New feature or request labels May 10, 2021
@bhrutledge
Copy link

The same is true with # noqa # fmt:skip (playground)

@hugolundin
Copy link

I'm having this issue aswell, with # fmt:skip isort:skip.

@jpchavat
Copy link

jpchavat commented Jun 3, 2022

Any workaround? same happen to me 😞

@seanbr76
Copy link

seanbr76 commented Jul 1, 2022

Try this

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

@jpchavat
Copy link

jpchavat commented Jul 2, 2022

Ik it works @seanbr76 , but seems too wordy to me.

@amirsalaar
Copy link

amirsalaar commented Dec 21, 2022

Try this

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

This only works for single cases. In my case, I have 7k lines in the code base that I am formatting which has # type: ignore and # noqa in some lines. The way to tackle fixing them in bulk is to use sed to prepend or append # fmt: skip to those lines.

@Deeprai32037i

This comment was marked as off-topic.

@Zacharias030
Copy link

Any progress on this?

@MestreLion
Copy link

Friendly inquiry about the status of this much-welcome (and needed!) feature... any progress?

This might be helpful: Pylint had similar issues a few years ago, and pylint-dev/pylint@daef49a and pylint-dev/pylint@b8f8c4a solved pylint-dev/pylint#2485 and others, allowing the pragma to begin or end with # or ; , so # noqa # pylint ... works as fine as # noqa; pylint ..., and lifting the "end of line" restriction, so # pylint ... # noqa works too!

Maybe their implementation can inspire a PR for Black?

@JelleZijlstra
Copy link
Collaborator

Thanks @henriholopainen for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: fmtskip fmt: skip implementation S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests