Search code examples
pythonpython-black

Can I undo the formatting style changes that Black makes to my Python code?


Does the Python formatting tool Black have an option for undoing the formatting changes it made after it's been run? Or does it assume I'm using source control and making my own backups? This is as of December 2019 and Black version 19.3b0.


Solution

  • No it does not. It does nothing more, but reformat the files it has been passed. It's simply a well behaved Unix tool and it expects you to handle your own version control.

    Its --diff option is the best you can get:

    --diff

    Don't write the files back, just output a diff for each file on stdout.

    Source: https://github.com/psf/black#command-line-options