jupyterlab_code_formatter icon indicating copy to clipboard operation
jupyterlab_code_formatter copied to clipboard

Indented magics don't parse

Open MarcoGorelli opened this issue 4 years ago • 3 comments

Checklist prior to opening an issue

  • [ ] I have followed fully the installation steps laid out in the documentation site.
  • [ ] I have restarted jupyterlab.
  • [ ] I have read the FAQ section in the documentation site.

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)

  • pip freeze

  • jupyter labextension list

  • jupyter serverextension list

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

Additional context Add any other context about the problem here.

MarcoGorelli avatar Jun 30 '21 19:06 MarcoGorelli

This issue is similar to this comment

terasakisatoshi avatar Jul 12 '21 05:07 terasakisatoshi

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 avatar Jul 12 '21 08:07 MarcoGorelli

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

MarcoGorelli avatar Aug 15 '21 15:08 MarcoGorelli