jupyterlab-contrib / jupyterlab_code_formatter

A JupyterLab plugin to facilitate invocation of code formatters.
https://jupyterlab-code-formatter.readthedocs.io/
MIT License
853 stars 55 forks source link

Indented magics don't parse #218

Open MarcoGorelli opened 3 years ago

MarcoGorelli commented 3 years ago

Checklist prior to opening an issue

Describe the bug A cell containing:

if True:
    %time 2+2

will throw:

Jupyterlab Code Formatter Error
Cannot parse: 2:4: %time 2+2

Diagnostic commands Please attach the output of the following commands (please format them properly)

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

terasakisatoshi commented 3 years ago

This issue is similar to this comment

MarcoGorelli commented 3 years ago

Another one is

print(
'%s'
% 'foo'
)

which gets transformed to

print(
    "%s"
    # %# 'foo'
)

But yeah, if black accept https://github.com/psf/black/pull/2357 then, jupyterlab_code_formatter could just call black.format_cell and this and the other similar issues would be solved

MarcoGorelli commented 3 years ago

https://github.com/psf/black/pull/2357 has been merged, so if/when they make a new release then this issue will be easily addressable