Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for percent format notebooks #4025

Open
Conchylicultor opened this issue Nov 6, 2023 · 1 comment
Open

Support for percent format notebooks #4025

Conchylicultor opened this issue Nov 6, 2023 · 1 comment
Labels
T: enhancement New feature or request

Comments

@Conchylicultor
Copy link

Conchylicultor commented Nov 6, 2023

In IPython / Jupyter notebook, trailing ; has a specific effect of suppressing the last output: https://ipython.org/ipython-doc/dev/interactive/tips.html#suppress-output

Other Colab extensions like https://github.com/google/etils also use ; to pretty display the line (as alias of the verbose IPython.display.display): https://etils.readthedocs.io/en/latest/ecolab.html#pretty-display-with-trailing

Colab/IPython notebook are meant for fast iteration. As such, those hack are very useful for fast visualization to be able to pretty display in Colab:

def fn():
  return x;  # Will display the return value

x = a + other_fn();  # Display `x`

Currently, when formatting a notebook file (e.g. a .py file with # %% cells), all ; get removed.

It would be great if there was a directive to force black keep the trailing ; locally on a file. Something like:

# fmt: disable=trailing-semicolon

Similar to # pylint: disable= directives.

As formatting is applied on the full codebase, but this behavior should only be ignored on some specific Colab/IPython files, Globally disabling this behavior is not an option. Instead, this would have to be disabled on a per-file basis.

@Conchylicultor Conchylicultor added the T: enhancement New feature or request label Nov 6, 2023
@Conchylicultor
Copy link
Author

Conchylicultor commented Nov 6, 2023

It looks keeping trailing ; is already implemented for .ipynb files: #3577

However this do not seems to work for .py files following the # %% format (.py files meant to be loaded in IPython):
https://jupytext.readthedocs.io/en/latest/formats-scripts.html#the-percent-format

Maybe this bug should be instead about supporting the # %% format on .py files, so that src/black/handle_ipynb_magics.py is applied in addition of the standard Python formatting.

@hauntsaninja hauntsaninja changed the title Option to disable auto-remove of ; Support for percent format notebooks Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant