Black: Pdb breakpoint line unnecessarily get formatted

Created on 5 Aug 2018  路  4Comments  路  Source: psf/black

The breakpoint set using pdb: import pdb; pdb.set_trace() get formatted into 3 lines:

import pdb

pdb.set_trace()

I'm using Atom editor with plugin to apply black when saving the file. 3 lines instead of single breakpoint line is not very convenient. Maybe it is possible to add an exclusion for such kind of lines?

Environment:
Operating system: macOS High Sierra; Version 10.13.6 (17G65)
Python version: 3.6.5
Black version: 18.6b4
Does also happen on master: yes

Most helpful comment

work around for python 3.7: use breakpoint() built-in https://docs.python.org/3/library/functions.html#breakpoint

All 4 comments

work around for python 3.7: use breakpoint() built-in https://docs.python.org/3/library/functions.html#breakpoint

It's unlikely we're going to make an exception for import pdb; pdb.set_trace() because that would introduce a considerable amount of complexity and it's really easy to just wrap this in # fmt: off # fmt: on if you really care about these two being on the same line IMO.

I agree with @pavdmyt that this would be nice to accomplish. Now I'm debugging some code, I add the pdb one liner and save, find the bug, and with the editors remove line functionality am clean again. With black that breaks up the workflow. I tried changing my pdb snippet into import pdb; pdb.set_trace() # fmt: off but that doesn't work.

Could we make single line escaping work then? That would allow this (quite common for me and my colleagues at least) workflow.

@tino -- What you want is the following:

# fmt: off
import pdb; pdb.set_trace()
# fmt: on

I've turned this into a snippet in VSCode so that all I have to do is type "pdb" as a prefix. You could do the same in your IDE for ease of use.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

odormond picture odormond  路  21Comments

lig picture lig  路  84Comments

bofm picture bofm  路  72Comments

rollschild picture rollschild  路  35Comments

underyx picture underyx  路  22Comments