You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
deffn():
returnx; # Will display the return valuex=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.
The text was updated successfully, but these errors were encountered:
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
changed the title
Option to disable auto-remove of ;
Support for percent format notebooks
Jan 7, 2024
Just to add to the use cases for this, we have notebooks in Myst Markdown and use jupytext --pipe black to format python code within those notebooks. Within that command, the markdown file gets converted into percent format for code formatting and then back to markdown. At the moment, that strips all of our semi-colons and it would be great if it didn't.
In IPython / Jupyter notebook, trailing
;
has a specific effect of suppressing the last output: https://ipython.org/ipython-doc/dev/interactive/tips.html#suppress-outputOther Colab extensions like https://github.com/google/etils also use
;
to pretty display the line (as alias of the verboseIPython.display.display
): https://etils.readthedocs.io/en/latest/ecolab.html#pretty-display-with-trailingColab/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:
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: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.
The text was updated successfully, but these errors were encountered: