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

Formatting: Format with Black, increase max line length to 100, combine multi-line blocks #178

Merged
merged 3 commits into from
Sep 23, 2022

Conversation

EwoutH
Copy link
Collaborator

@EwoutH EwoutH commented Sep 23, 2022

This PR does 3 thing, each in a separate commit:

  • Formats all code with Black (black)
  • Formats all code with Black with an increased line limit of 100 characters (from the default 88) (black --line-limit 100)
  • Formats all code with Black with an increased line limit while removing trailing commas (black --line-limit 100 -C)

In each commit some edge cases were by hand removed to retain the best readability. The code now fully follows Black formatting.

The 100 character line limit was chosen because it increases readability by offering more code in a single view and allows for slightly longer (and thus more descriptive) variable names without expanding code to multiple lines.

The trailing comma handling by Black is is worth explaining a little. If Black detects a trailing comma, such as

dict1 = {
    a: 1,
    b: 2,
}

it won't format the code to a single line. But if it doesn't detect a trailing comma, it does. So

dict1 = {
    a: 1,
    b: 2  # Note no comma here
}

becomes

dict1 = {a: 1, b: 2}

This way you can control if you would like your code to stay in multi-line or be reduced to a single line.

@quaquel Could you let me know if you A) agree with the increased line limit of 100 characters and B) find that this improved readability generally? (I checked everything by hand but just for sure)

(please let me merge if everything is ok)

Formats all files with Black. Uses default line-limit of 88 characters.

A lot of trailing commas were removed manually.
Format all code with Black using a line-limit of 100. This shortens many multi-line code blocks to a single line, making them more compact readable.
Remove trailing commas to combine multiple lines to a single line. A few edge-cases in which this degraded readability were not included (not visible in this commit). This should make code more compact while retaining or improving readability.

Command used: black --line-length 100 -C

See https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#trailing-commas
@EwoutH EwoutH added this to the 2.3.0 milestone Sep 23, 2022
@EwoutH EwoutH requested a review from quaquel September 23, 2022 13:44
@coveralls
Copy link

Coverage Status

Coverage remained the same at 80.051% when pulling ab3a28e on black-formatting into abfaafb on master.

@quaquel
Copy link
Owner

quaquel commented Sep 23, 2022

I like the way black handles the trailing comma and how you can use it to retain readability. I was wondering about this in the context of #170, so thanks for clarifying.

I am torn on increasing the line limit. On the one hand, I agree with the improved readability. On the other hand, I often work on a laptop and then you can quickly run out of screen space in an IDE. 100 characters might offer a reasonable balance between these two concerns.

@quaquel quaquel mentioned this pull request Sep 23, 2022
3 tasks
@EwoutH EwoutH merged commit 4f0ae67 into master Sep 23, 2022
@EwoutH EwoutH deleted the black-formatting branch September 26, 2022 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants