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

Comments between fmt:on/off are reformatted #1245

Open
marcelm opened this issue Jan 23, 2020 · 7 comments
Open

Comments between fmt:on/off are reformatted #1245

marcelm opened this issue Jan 23, 2020 · 7 comments
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. F: fmtoff fmt: off implementation T: bug Something isn't working

Comments

@marcelm
Copy link

marcelm commented Jan 23, 2020

This code:

# fmt: off
 #nospace
 #  twospaces
# fmt: on

is changed to:

# fmt: off
# nospace
#  twospaces
# fmt: on

I expected the lines betwen # fmt: off and # fmt: on to remain unchanged.

  • Version: master (19.10b1.dev22+gbe49ac7)
  • OS: Ubuntu Linux
  • Python: 3.6.9

Playground (master)

@marcelm marcelm added the T: bug Something isn't working label Jan 23, 2020
@steve-biggs-fox
Copy link

steve-biggs-fox commented Jul 21, 2020

This bug is affecting me too as my python code contains supercomputer queue manager options that must be formatted like "#PBS (option)" with no space between "#" and "PBS". As a workaround, a print statement within the "# fmt: off/on" block makes it work but ideally blocks of comments only within a "# fmt: off/on" block with no executable code in the block should still respect the "# fmt: off/on" directive.

@JelleZijlstra
Copy link
Collaborator

An interesting case from a duplicate:

class A:
    ........

    minutes_available_per_week = models.PositiveIntegerField(
        # fmt: off
        default=settings.TIME_ESTIMATES["defaults"]["minutes_available_per_week"]  # type: ignore
        # fmt: on
    )

@ichard26 ichard26 added the F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. label May 30, 2021
@petergthatsme
Copy link

I was just wondering if there were any updates related to this bug report.
I also find this bug problematic. My usecase is the following: I have some code that needs to be temporarily commented out (say for a few days), while other code in the file is added/modified. Using black then reformat the commented code, which completely looses its indentation, making it useless even after removing the comments.
The workaround is to add, say, pass somewhere next to the commented code, but it would be great if that wasn't required.
thanks.

@aljabadi
Copy link

Thanks for creating the best opinionated formatter I've used.

I'm having this issue with setup.cfg file:

# fmt: off
[metadata]
name = appname
description = a project
long_description = file: README.md
long_description_content_type = text/markdown
charset=UTF-8
author = Al J Abadi
author_email =foo@company.com
classifiers =
    Development Status :: 2 - Pre-Alpha 
    Environment :: Console
    Environment :: MacOS X
    Intended Audience :: Developers
    Natural Language :: English
    Operating System :: POSIX :: Linux
    Operating System :: MacOS :: MacOS X
    Programming Language :: Python :: 3.7
    Programming Language :: Python :: 3.8
    Programming Language :: Python :: 3.9
    Topic :: Scientific/Engineering :: Data Science

[options]
zip_safe = False
packages = find:
platforms = any
include_package_data = True
install_requires =
    bz2file
python_requires = >=3.7
setup_requires =
    setuptools_scm

[bdist_wheel]
universal = 1
# fmt: on

The indentation is required for a successful build but it is removed by black. I was surprised this issue still persists after such a long time.

@felix-hilden
Copy link
Collaborator

@aljabadi I don't think we format CFG files 🤔

@SomeoneSerge
Copy link

SomeoneSerge commented Jun 1, 2022

Another use-case that's affected:

#!/usr/bin/env python3
# fmt: off
#SBATCH --job-name="Example"
#SBATCH --array=0-250
# ...
# fmt: on

Black alters #SBATCH into # SBATCH. The former is interpreted by SLURM, the latter ignored

EDIT: already reported in #1024

@randolf-scholz
Copy link

Same issue here: Playground link

Input

rawdata_schema = {
    # fmt: off
    "No"      : "uint16[pyarrow]",
    "year"    : "uint16[pyarrow]",
    "month"   : "uint8[pyarrow]",
    "day"     : "uint8[pyarrow]",
    "hour"    : "uint8[pyarrow]",
    "PM2.5"   : "float32[pyarrow]",
    "PM10"    : "float32[pyarrow]",
    "SO2"     : "float32[pyarrow]",
    "NO2"     : "float32[pyarrow]",
    "CO"      : "float32[pyarrow]",
    "O3"      : "float32[pyarrow]",
    "TEMP"    : "float32[pyarrow]",
    "PRES"    : "float32[pyarrow]",
    "DEWP"    : "float32[pyarrow]",
    "RAIN"    : "float32[pyarrow]",
    "wd"      : "string",  # FIXME bug in pandas prevents using pyarrrow here.
    "WSPM"    : "float32[pyarrow]",
    "station" : "string",  # FIXME bug in pandas prevents using pyarrrow here.
    # fmt: on
}

Output

rawdata_schema = {
    # fmt: off
    "No"      : "uint16[pyarrow]",
    "year"    : "uint16[pyarrow]",
    "month"   : "uint8[pyarrow]",
    "day"     : "uint8[pyarrow]",
    "hour"    : "uint8[pyarrow]",
    "PM2.5"   : "float32[pyarrow]",
    "PM10"    : "float32[pyarrow]",
    "SO2"     : "float32[pyarrow]",
    "NO2"     : "float32[pyarrow]",
    "CO"      : "float32[pyarrow]",
    "O3"      : "float32[pyarrow]",
    "TEMP"    : "float32[pyarrow]",
    "PRES"    : "float32[pyarrow]",
    "DEWP"    : "float32[pyarrow]",
    "RAIN"    : "float32[pyarrow]",
    "wd"      : "string",  # FIXME bug in pandas prevents using pyarrrow here.
    "WSPM"    : "float32[pyarrow]",
    "station" : "string",
    # FIXME bug in pandas prevents using pyarrrow here.
    # fmt: on
}

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 T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants