question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pre-commit/black is getting in the way too much

See original GitHub issue

It is annoying to get interrupted with something like:

% gc
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /home/user/.cache/pre-commit/patch1583628686.
black....................................................................Failed
- hook id: black
- files were modified by this hook
[20+ lines deleted]
[INFO] Restored changes from /home/user/.cache/pre-commit/patch1583628686.

to see that black did turn it into something less readable (since it does not recognize “exploding commas” with function calls):

-    result.stdout.fnmatch_lines([
-        'E       assert False',
-        '*- Captured stdout call -*',
-        'hello',
-    ])
+    result.stdout.fnmatch_lines(
+        ["E       assert False", "*- Captured stdout call -*", "hello",]
+    )

Therefore I think it would be more sensible to either exclude black from the pre-commit config altogether, or not to recommend installing pre-commit in the first place.

I think it is fine to enforce checks on CI, but that could/should be limited to flake8 etc only, and black could be run then in the release process.

Black is meant to have consistent output for things being committed, but it does not help if you have to add # fmt: {on,off} (after being interrupted), or just accept that it is less readable etc. I.e. in the second case it certainly causes code to be less readable / and more affected to diff churn (when tests get hardened/changed with regard to their output).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
RonnyPfannschmidtcommented, Mar 8, 2020

i consider black a integral part of keeping certain review overheads low, i’m not going to agree with removing it

0reactions
nicoddemuscommented, Mar 28, 2020

Sure, sorry, but either way you are definitely free to uninstall pre-commit and run tox -e linting manually, but we should not recommend that in general, as people often get it wrong.

Read more comments on GitHub >

github_iconTop Results From Across the Web

black as pre-commit hook always fails my commits
What actually happens when I stage a (non-black-compliant) file and try to commit: Black goes ahead and modifies the file to make it...
Read more >
Keep your code clean using Black & Pylint & Git Hooks & Pre ...
In this article, we will see how to do so as a pre-commit step using git hooks. Table of content. The summary is...
Read more >
Automate Python workflow using pre-commits: black and flake8
I'll first discuss the pre-commit framework, then add components one-by-one: first is black , and then flake8 . I will show the dotfiles...
Read more >
pre-commit
As we created more libraries and projects we recognized that sharing our pre-commit hooks across projects is painful. We copied and pasted unwieldy...
Read more >
Data Science Toolbox: Black + Pre-commit | by Tom Titcombe
Imagine you've just completed work on a large feature: you push your work and head off to take that much deserved tea break....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found