0

I am using Black with Python 3.7 (in VS Code).

When I format my code, the numeric literals are normalized with the underscore (e.g. 1562202 => 1_562_202).

How to use Black Formatting without formatting by using the underscore?

NOTE From black version 19.2b, this question becomes obsolete.

Jean-Francois T.
  • 11,549
  • 7
  • 68
  • 107

2 Answers2

5

To avoid formatting literals, use black --skip-numeric-underscore-normalization or the short flag, black -N

You can make this a permanent change by modifying your pyproject.toml file:

[tool.black]
skip-numeric-underscore-normalization = true

https://github.com/ambv/black#189b0

Russell Cohen
  • 717
  • 4
  • 7
0

As mentionned in the official documentation of Black, the following option can skip adding underscore in numeric literals:

-N, --skip-numeric-underscore-normalization Don't normalize underscores in numeric literals.

In VS Code, just add the following option in your User Settings JSON file:

"python.formatting.blackArgs": ["--skip-numeric-underscore-normalization"]
Jean-Francois T.
  • 11,549
  • 7
  • 68
  • 107