ipython-contrib / jupyter_contrib_nbextensions

A collection of various notebook extensions for Jupyter
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest
Other
5.22k stars 806 forks source link

Use `black` formatter by default #1452

Open lucatrv opened 5 years ago

lucatrv commented 5 years ago

Based on: https://gist.github.com/MarvinT/a072aa992e977496974aaf492287b08c#file-black_code_prettify-json

jcb91 commented 5 years ago

Although I like this idea, it looks like the black API has changed recently, so this doesn't always work. On my current installation (black 19.3b0), this throws

TypeError: format_str() takes 1 positional argument but 2 were given

while the method signature appears to expect a filemode dataclass object (see https://github.com/psf/black/blob/19.3b0/black.py#L664). It looks like your version would have worked with the previous API from 18.9b0 (see https://github.com/psf/black/blob/18.9b0/black.py#L621-L623). I guess this is what we get for black still being "beta". A small try/except could probably cover both versions?

Thanks for the PR, btw 👍

lucatrv commented 5 years ago

That's strange, it's working on me with black 19.3b0. I'm on Windows 7, with Miniconda on "conda-forge" channel.

jcb91 commented 5 years ago

Hmm, curiouser & curiouser. I'm on macOs, using 19.3b0 from PyPi. I'll try to give it a shot on windows at some point. Alternatively, perhaps it would be worth adding python tests for these snippets...

shunkakinoki commented 4 years ago

Really great idea!

lucatrv commented 4 years ago

Now it works with the new Black API.

inarighas commented 11 months ago

Thanks for this PR. Is it ready to be merged ?

lucatrv commented 11 months ago

I think it has been for a while already...