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

# fmt: off fails to stop formatting on a comment block #2329

Closed
fpdotmonkey opened this issue Jun 11, 2021 · 1 comment
Closed

# fmt: off fails to stop formatting on a comment block #2329

fpdotmonkey opened this issue Jun 11, 2021 · 1 comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. F: fmtoff fmt: off implementation R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@fpdotmonkey
Copy link

fpdotmonkey commented Jun 11, 2021

Describe the bug

I have this file header in my source that I'd like to not mess with since it's got license information for code that isn't mine. So I wrap it in # fmt: off; ...; # fmt: on to preserve the block, but the block gets formatted anyway (a space gets added after the #).

Before black:

# fmt: off
#===- cindex-dump.py - cindex/Python Source Dump -------------*- python -*--===#
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===------------------------------------------------------------------------===#
# fmt: on

After black:

# fmt: off
# ===- cindex-dump.py - cindex/Python Source Dump -------------*- python -*--===#
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# ===------------------------------------------------------------------------===#
# fmt: on

To Reproduce

  1. Put the top code block in a file
  2. Run Black on it
  3. Code gets formatted

Expected behavior

Code doesn't get formatted

Environment (please complete the following information):

  • Version: __main__.py, version 20.8b1
  • OS and Python version: Ubuntu 18.04.5 LTS, Python 3.6.9

Does this bug also happen on main?

@JelleZijlstra JelleZijlstra added the F: fmtoff fmt: off implementation label Jun 11, 2021
@ichard26 ichard26 added F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. R: duplicate This issue or pull request already exists T: bug Something isn't working labels Jun 11, 2021
@ichard26
Copy link
Collaborator

Hey, thanks for reporting the bug! Unfortunately (or fortunately?) this is a duplicate of #1245 so I'll be closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. F: fmtoff fmt: off implementation R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants