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

Black is not honoring fmt: off for comment changes #3537

Open
nijel opened this issue Feb 1, 2023 · 1 comment
Open

Black is not honoring fmt: off for comment changes #3537

nijel opened this issue Feb 1, 2023 · 1 comment
Labels
T: bug Something isn't working

Comments

@nijel
Copy link

nijel commented Feb 1, 2023

Describe the bug

black since 23.1.0 breaks Munin magic markers without a way to override.

To Reproduce

For example, take this code:

# fmt: off
#%# family=auto
#%# capabilities=autoconf
# fmt: on

And run it with these arguments:

$ black file.py

The resulting output is:

# fmt: off
# %# family=auto
# %# capabilities=autoconf
# fmt: on

Expected behavior

The block between fmt: off and fmt: on should not be changed.

Environment

  • Black's version: 23.1.0
  • OS and Python version: Linux/Python 3.11

Additional context

Seem to be related to #2919, it might be a separate bug there as well, as it talks only about #%% (note the double %). So, it might be two bugs here:

  • fmt: off not honored
  • #%% formatting being actually applied to #%
@scotran
Copy link

scotran commented Feb 3, 2023

Taking a look at this. This seems like part of a known limitation noted in the fmtonoff.py tests: some comments in between fmt: off and fmt: on, it's a weird issue. A simple fix would just include % as part of the comment exceptions, COMMENT_EXCEPTIONS, but might go against what the previous commit wanted - if this is fine, then that's an easy fix. The bigger fix would be to fix comment formatting in between fmt: off/on altogether.

nijel added a commit to WeblateOrg/munin that referenced this issue Apr 5, 2023
This is still broken, but at least this code is supposed to work.

See psf/black#3537
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants