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

STY: use black #26926

Closed
jreback opened this issue Jun 18, 2019 · 11 comments
Closed

STY: use black #26926

jreback opened this issue Jun 18, 2019 · 11 comments
Labels
Code Style Code style, linting, code_checks

Comments

@jreback
Copy link
Contributor

jreback commented Jun 18, 2019

I have seen a number of other project adopt: https://pypi.org/project/black/, as well as use in my company.

This basically is a style formatter that plays nice with flake8 and is completely opionated, the only option is line-length. This is a good thing.

This would involve a one-time updating of code (though we can do it somewhat incrementally).

@jreback jreback added the Code Style Code style, linting, code_checks label Jun 18, 2019
@jreback jreback added this to the Contributions Welcome milestone Jun 18, 2019
@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jun 18, 2019 via email

@jorisvandenbossche
Copy link
Member

Could we start with requiring it for new code? (assuming black has a reformat-diff-only option)

@simonjayhawkins
Copy link
Member

+1 in principle

just tried it with VSCode extension.

can't apply to a selection, not a problem if code is already blackened.

                                raise ValueError('cannot convert float '
                                                 'NaN to integer')
                                raise ValueError(
                                    "cannot convert float " "NaN to integer"
                                )

may want a second pass to tidy things like this.

from pandas.core.dtypes.generic import (
    ABCDataFrame, ABCDateOffset, ABCDatetimeArray, ABCIndexClass,
    ABCMultiIndex, ABCPandasArray, ABCPeriodIndex, ABCSeries,
    ABCTimedeltaArray, ABCTimedeltaIndex)
from pandas.core.dtypes.generic import (
    ABCDataFrame,
    ABCDateOffset,
    ABCDatetimeArray,
    ABCIndexClass,
    ABCMultiIndex,
    ABCPandasArray,
    ABCPeriodIndex,
    ABCSeries,
    ABCTimedeltaArray,
    ABCTimedeltaIndex,
)

may need a test to make sure it plays nice with isort

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jun 18, 2019 via email

@Batalex
Copy link
Contributor

Batalex commented Jun 20, 2019

If it helps in any way, here is an isort config which plays fine with black and pre-commit in my projects

[settings]
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
combine_as_imports=True
line_length=88

@jorisvandenbossche
Copy link
Member

So we discussed it last week on the call, and no strong objections were raised (and indeed, it does deliberately not support only blackening the diff to do it incrementally).

So we will try to push this during the sprints now.

@vaibhavhrt
Copy link
Contributor

vaibhavhrt commented Jun 28, 2019

I don't think 80 char limit should be increased. When working with two files side by side, in Editors like VS Code, 80 characters lines fits perfectly. Hence you can work with two files at a time(which is handy like almost all the time) without having to scroll sideways.
Something like this:
vscode
The laptop I am on rn is kinda small, so I can't even fit 80 chars properly. But on my other laptop it fits

@simonjayhawkins
Copy link
Member

i'd also be happier with not increasing the line length. the standard 79 chars would be good.

for accessibility I prefer to have larger fonts, so regardless of the laptop resolution, the shorter line length helps with side by side files.

@jorisvandenbossche
Copy link
Member

I personally like the somewhat longer line length, but certainly understand those arguments to keep it at 79 (I also regularly have files side by side, and it gets more tight in that way).

With the tendency of black to create more horizontal lines, I think it is nice to use their default of 88. And as Tom said above with adding more typing annotations, a longer line length can also help there.

There is one practical problem with changing their default. Black uses a pyproject.toml for config, and once you have such a file, pip will also use it. So that would mean we first need to to finish up #25227.

@simonjayhawkins
Copy link
Member

There is one practical problem with changing their default. Black uses a pyproject.toml for config, and once you have such a file, pip will also use it. So that would mean we first need to to finish up #25227.

Although not the recommended approach, would using the pre-commit hook skirt this issue? https://black.readthedocs.io/en/stable/version_control_integration.html#version-control-integration

@jbrockmendel
Copy link
Member

Closable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks
Projects
None yet
Development

No branches or pull requests

7 participants