Skip to content

Whitespace before fmt: skip comment is normalised #4143

@m-czernek

Description

@m-czernek

Describe the bug

Apologies if this is a duplicate; I have read:

Based on #3959, Black should support e.g. this: # pylint: disable=redefined-outer-name # fmt: skip and yet I cannot get it to work on the newest Black version.

I have the following line:

client = billingdataservice.app.test_client() # pylint: disable=redefined-outer-name

The line is too long for black, so when I run black, I get this:

client = (
    billingdataservice.app.test_client()
)  # pylint: disable=redefined-outer-name

We don't want that, so I tried to use fmt: skip. I tried the following comments:

  • client = billingdataservice.app.test_client() # pylint: disable=redefined-outer-name; fmt: skip
  • client = billingdataservice.app.test_client() # pylint: disable=redefined-outer-name # fmt: skip
  • client = billingdataservice.app.test_client() # fmt: skip # pylint: disable=redefined-outer-name
  • client = billingdataservice.app.test_client() # fmt: skip; pylint: disable=redefined-outer-name

as well as mixing number of spaces before/after the hash sign, e.g. ...test_client() # fmt: skip; pylint: ... or ...test_client() # fmt: skip; pylint: ... etc.

Reproducer

file.py:

def client():
    client = billingdataservice.app.test_client() # fmt: skip; pylint: disable=redefined-outer-name

Command:

$ black --preview file.py

(The --preview flag seems not to matter for this issue; behavior is identical with or without it)

Black always modifies the line, e.g.:

def client():
    client = ( 
        billingdataservice.app.test_client()
    )  # fmt: skip; pylint: disable=redefined-outer-name

Which means fmt: skip did not get honored.

Environment

$ black --version
black, 23.12.1 (compiled: yes)
Python (CPython) 3.11.6
  • Black's version: 23.12.1
  • OS and Python version: OpenSUSE Tumbleweed, Python 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: fmtskipfmt: skip implementationT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions