1

in my pre-commit-config.yaml file i'm trying to run black, the python code formatter

repos:
-   repo: https://github.com/python/black
    rev: stable
    hooks:
    - id: black
      language_version: python3.6

but whenever I tried running black with pipenv run pre-commit --all the code will fail with the error message

An unexpected error has occurred: AttributeError: type object 'Hook' has no attribute 'create'
Check the log at some_path

when I go to some_path I couldn't find any logs there. I tried not running the pipenv run pre-commit --all to apply black to my code, but the error still appears when I try to git commit any new files. Any ways to solve this?

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
Chia Yi
  • 562
  • 2
  • 7
  • 21
  • I have the same issue, i'm currently trying to understand the issue. Did you have any success since the problem occured ? – Guibod Feb 06 '20 at 13:38

3 Answers3

0

I've encountered this issue using python 3.6.0, i've moved up to python 3.6.9 and this error is no more.

Guibod
  • 371
  • 1
  • 3
  • 13
0

I didn't try upgrading my python but I tried the steps below and it worked for me

1. pipenv shell
2. pip install black
3. black name_of_the_directory_you_want_to_format
Chia Yi
  • 562
  • 2
  • 7
  • 21
0

This was a bug with python 3.6.0 (this exact patch version) and pre-commit between versions 2.0.0 and 2.1.0

This was fixed in 2.1.1: https://github.com/pre-commit/pre-commit/blob/master/CHANGELOG.md#211---2020-02-24


disclaimer: I'm the author of pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207