Skip to content

Autoformat with black - #11734

Merged
Carreau merged 4 commits into
ipython:masterfrom
Carreau:autoformat-black
Nov 21, 2019
Merged

Carreau merged 4 commits into
ipython:masterfrom
Carreau:autoformat-black

Conversation

@Carreau

@Carreau Carreau commented May 16, 2019

Copy link
Copy Markdown
Member

@stonebig

stonebig commented May 18, 2019 •

Copy link
Copy Markdown
Contributor

I replaced shortcuts.py per this one, but nothing happens in ipython notebook (and windows)...
Black is there... did I miss something ?
image

@stonebig

stonebig commented May 18, 2019 •

Copy link
Copy Markdown
Contributor

ah, .. it works only on ipython "DOS" console , for the moment.
It looks nice on a few lines of code.
GIF

@LucianaMarques LucianaMarques left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not getting where you are checking whether black is installed, could you please point it out for me? :) Thanks!

Comment thread IPython/terminal/shortcuts.py Outdated

def newline_or_execute_outer(shell):

import black

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, why is this here and not above with all the other modules being imported?

Comment thread IPython/terminal/shortcuts.py Outdated
"""When the user presses return, insert a newline or execute the code."""
b = event.current_buffer
d = b.document
def try_reformat():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a little bit confusing to define a function inside of another function. Could you please tell me whether there's a specific reason for this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For both of your questions the answer is : "there is no reason beyond pure lazyness", I was prototyping and looking at "can this be done"; you are right that a proper implementation should move the import to the top of the file and define the try_reformat() function outside, passing in the b buffer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fair enough :)

How do you check whether black is activated?

@Carreau
Carreau force-pushed the autoformat-black branch from a81e165 to e962a2b Compare July 7, 2019 04:30
@Carreau Carreau changed the title [WIP] autoformat with black Autoformat with black Nov 17, 2019
@Carreau

Carreau commented Nov 17, 2019

Copy link
Copy Markdown
Member Author

I've pushed some update, including some documentation; and will try to get that in a a preview for 7.10 at end of month.

@Carreau
Carreau merged commit 17e9ca6 into ipython:master Nov 21, 2019
@Carreau
Carreau deleted the autoformat-black branch November 21, 2019 19:10
@Carreau Carreau modified the milestones: no action, 7.10 Nov 21, 2019
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

Successfully merging this pull request may close these issues.

3 participants