peterjc / flake8-black

flake8 plugin to run black for checking Python coding style
MIT License
165 stars 10 forks source link

BLK999 Unexpected exception: format_file_contents() ... #3

Closed peterjc closed 5 years ago

peterjc commented 5 years ago

Just seen on a TravisCI run for code which passed locally,

...
Collecting black (from flake8-black)
  Downloading https://files.pythonhosted.org/packages/30/62/cf549544a5fe990bbaeca21e9c419501b2de7a701ab0afb377bc81676600/black-19.3b0-py36-none-any.whl (89kB)
...
BLK999 Unexpected exception: format_file_contents() got an unexpected keyword argument 'line_length'

https://travis-ci.org/peterjc/thapbi-pict/builds/506882383

Looks like a side effect from black 19.3b0, or at least a recent version of black which removed this argument to the format_file_contents function.

Update: Confirmed, new version of black broke this

peterjc commented 5 years ago

Its a big commit so may not render nicely on GitHub:

https://github.com/ambv/black/commit/36d3c516d3c09fc5f05c420900dd6b854e3c8bbd

The raw patch view is clear enough:

https://github.com/ambv/black/commit/36d3c516d3c09fc5f05c420900dd6b854e3c8bbd.patch

@@ -596,11 +647,7 @@ def format_stdin_to_stdout(

 def format_file_contents(
-    src_contents: str,
-    *,
-    line_length: int,
-    fast: bool,
-    mode: FileMode = FileMode.AUTO_DETECT,
+    src_contents: str, *, fast: bool, mode: FileMode
 ) -> FileContent:
     """Reformat contents a file and return new contents.
peterjc commented 5 years ago

Must now pass in the line length via the mode argument, an instance of the new FileMode class.

peterjc commented 5 years ago

Short term solution is pip install black==18.9b0 (the previous release on PyPI).

peterjc commented 5 years ago

Fixed in v0.0.4, now on PyPI