Skip to content

Consider using black as an autoformatter #18796

Closed
@ianhi

Description

@ianhi

Problem

I find flake8 errors to be confusing to fix at times. For example, I've expended more mental energy than I care to admit trying to figure out how to turn an 81 character line into two lines. This feels like it makes more difficult to contribute to matplotlib, especially for someone who hasn't gone to the trouble of setting up an ide to point out flake8 errors. More difficult both through the extra mental effort and the extra back and forth about formatting on PRs.

Proposed Solution

Autoformat all code using black. This would remove the mental burden of formatting by having contributors only need to run:

black .

Additional context and prior art

  1. Plunging the depths for flake8 commits: (those that never got squashed)

git log --all | grep "flake" -c -i
169

git log --all | grep "fix.*format" -c -i
259

  1. If done in a single commit then the commit can be saved in git-blame-ignore-revs to avoid messing up git blame (though I suppose it may be messed up on github :/ )
    https://black.readthedocs.io/en/stable/installation_and_usage.html#migrating-your-code-style-without-ruining-git-blame

  2. We did this on jupyterlab-git (Format code using black jupyterlab/jupyterlab-git#763) and it has sparked me trying to use this everywhere I can

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions