black icon indicating copy to clipboard operation
black copied to clipboard

`# fmt: skip` is not being respected with one-liner functions

Open polirritmico opened this issue 1 year ago • 4 comments

Describe the bug

Hi, # fmt: skip doesn't skip the formatting in this code:

def foo(): return "mock"  # fmt: skip
$ black foo.py; cat foo.py

Output:

def foo():
    return "mock"  # fmt: skip

Similar case in the playground.

Expected behavior

From the docs I understand that Black should not reformat lines that contain # fmt: skip (The basics -> Usage -> Ignoring sections).

Environment

  • Black's version: 24.10.0 (compiled: yes), 24.10.1.dev22+g6000d37 (compiled: no)
  • OS and Python version: Gentoo Linux 2.17, Python 3.12.8

Thanks!

polirritmico avatar Dec 21 '24 01:12 polirritmico

Hey

I tried to run the code The output:

def foo(): return "mock" # fmt: skip

Its seems that the #fmt: skip is not behaving as expected Its the bug in Black ,is there anything to resolve this bug Is there anything to fix this bug

Thanks Fardeen khan

FARDEEN-785 avatar Jan 18 '25 02:01 FARDEEN-785

nstead of applying # fmt: skip at the end of a single line, apply it above the function definition as part of a block comment:

fmt: off

def foo(): return "mock"

fmt: on

This explicitly disables Black formatting for the entire block, ensuring that the function remains on one line.

saksham-sak avatar Jan 30 '25 16:01 saksham-sak

@saksham-sak, this issue is about # fmt: skip not respecting the documented behaviour.

polirritmico avatar Jan 30 '25 16:01 polirritmico

@saksham-sak you appear to be posting LLM-generated responses to a number of issues. It's not useful; please stop.

JelleZijlstra avatar Jan 30 '25 19:01 JelleZijlstra