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

IPython shell examples #127

Open
adamchainz opened this issue Nov 8, 2021 · 3 comments
Open

IPython shell examples #127

adamchainz opened this issue Nov 8, 2021 · 3 comments

Comments

@adamchainz
Copy link
Owner

I tend to use IPython shell examples rather than the plain Python console, and I'd like blacken-docs to format them, e.g.

 .. code-block:: ipython

-    In [1]: print('Hello World')
+    In [1]: print("Hello World")
     Hello World

     In [2]: print(
-       ...: 'Hello World'
+       ...: "Hello World"
        ...: )
     Hello World

Would this be an accepted feature? Happy to give it a shot if so.

@asottile
Copy link
Contributor

asottile commented Nov 8, 2021

if you want to make it work and maintain it sure

@MarcoGorelli
Copy link

The tricky part here is dealing with IPython magics, such as %%timeit, which aren't valid Python syntax

Just bringing up black's IPython magic handler, in case it's useful https://github.com/psf/black/blob/main/src/black/handle_ipynb_magics.py (perhaps it's even possible to do this reusing black.format_cell?)

@adamchainz
Copy link
Owner Author

This may be somewhat redundant, since IPython has the ability to run Black on input lines during execution. It doesn't help with reformatting existing shell sessions but it covers creating them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants