Search code examples
pythonpython-3.xpython-black

With Python Black (prior to 19.2b), how to skip normalizing underscores in numeric literals?


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.


Solution

  • 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"]