Thanks to visit codestin.com
Credit goes to github.com

Skip to content

STY: make allowed line length 9 longer to 88 from 79 #24893

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

Merged
merged 4 commits into from
Jan 26, 2023

Conversation

tacaswell
Copy link
Member

As discussed on the call this week, we should consider making the style enforced line length slightly longer.

Going to 88 matches the default of black. https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length is a nice explanation of how they landed there.

Key points from the call:

  • we should keep this low enough that GH's side-by-side diff view works
  • keep this small enough 2 or 3 panels can be up next to each other in an editor
  • we can make it bigger in the future, but making it smaller would be rough

There are no plans to re-flow the entire code base, but new stuff could come in more relaxed.

@tacaswell tacaswell added this to the v3.8.0 milestone Jan 6, 2023
@jklymak
Copy link
Member

jklymak commented Jan 6, 2023

I guess we should have some sort of policy about reflow PRs. I'm not looking forward to 100s of those (or a few giant ones).

@timhoffm
Copy link
Member

timhoffm commented Jan 6, 2023

For now, let's not do any reflow at all. Only new / changed code should use the increased line length.

IMHO many small reflow PRs do not make sense. We can later decide whether we want to do one large one, possibly related to the decision whether we want to use black style.

@oscargus
Copy link
Member

oscargus commented Jan 6, 2023

I'd say that the policy is:

  1. Do not reflow just for the sake of it.
  2. If one reflows a (large) doc-string when editing it, split it into two commits:
    1. The actual change
    2. The reflow

(For code I expect that there will be fewer changes in practice.)

@anntzer
Copy link
Contributor

anntzer commented Jan 9, 2023

Sorry I missed the call, but can one briefly remind what arguments were put forward in favor of this change?
I guess I'm relatively indifferent to switching to 88 (staying small enough to make side-by-side diffs is indeed important, but 88 is OK), but would not want to see this as a stepping stone towards moving to black style.

In particular I find black's argument (https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length)

This number was found to produce significantly shorter files than sticking with 80 (the most popular), or even 79 (used by the standard library). In general, 90-ish seems like the wise choice.
If you’re paid by the line of code you write, you can pass --line-length with a lower number. Black will try to respect that.

quite dishonest, given that black tends to produce many, many lines with just punctuation (e.g. closing parentheses and brackets), so if you care about file length you should just not put trailing punctuation on its own line and you'll save much more than by bumping the line length limit from 79 to 88.

In fact, sometimes in Matplotlib we do put trailing punctuation by itself on a separate line, but the whole point is that it depends on the semantics of the code, and is not something we do all the time.

@oscargus
Copy link
Member

oscargus commented Jan 9, 2023

I must stress that although I sometimes use black in projects (because other people encourage it or are really bad at manual formatting), I do tend to be quite appalled quite a lot of the time, so I also hope that this change is not a step in that direction.

(I hope/guess that the argument is that doc-strings can sometimes be quite narrow if they show up on a high tab-level. Also, many nested tab-levels combined with long variable names sometimes make it hard to avoid doing ... = (\n. But did't attend either.)

@timhoffm
Copy link
Member

timhoffm commented Jan 9, 2023

While I have an ambivalent opinion on black, the line length choice seems reasonable.

Maybe black's explanation is a bit sloppy. IMHO less number of lines (=more content on the screen) is only the secondary reason for longer lines. The greater benefit of less wrapping is more "one line = one statement", which increases readability - as long as the lines are not too long.

I also have the feeling that 79 is a bit too tight. If black has found out that 88 chars produce significant less wrapping, that's a valuable result, irrespective of their other style decisions. Unless we have good reasons for a different line length, I think 88 is a good number.

@jklymak
Copy link
Member

jklymak commented Jan 9, 2023

On the call, there was no question of actually starting to use black, just that it was reasonable to choose a line length consistent with their default. The original proposal was a line length of 115. Definitely, any discussion about switching to black would be very broad.

@tacaswell
Copy link
Member Author

You can also increase it, but remember that people with sight disabilities find it harder to work with line lengths exceeding 100 characters. It also adversely affects side-by-side diff review on typical screen resolutions. Long lines also make it harder to present code neatly in documentation or talk slides.

This was the part of the black documentation I was trying to reference.

@oscargus
Copy link
Member

(I can just note that assembly rarely has the issue of line length...)

Is this ready to review now that 3.7 is branched? There seems to be some sort of common understanding in the discussions here as well:

  • Slightly longer lines are good
  • Black is not always good and not the goal

Only question is if we should document any policy about reflowing? I may doubt that the average contributor may not note this. There are currently some (parts of) files which could be reflowed and I have not seen any such PRs during my year involved so I do not really think that we should expect that many now. If we do, we can add a policy?

@rcomer
Copy link
Member

rcomer commented Jan 10, 2023

I would have thought that the vast majority of contributors have no more interest in writing a reflow PR than we have in reviewing one. For any that do, I think it would be reasonable to respond along the lines of “the benefits of this change do not outweigh the effort of reviewing it or the risk of unintended functional changes”, without needing to point to a specific written policy.

The PR guidelines currently state that we conform to PEP8, so possibly that text should be tweaked.

@tacaswell
Copy link
Member Author

tacaswell commented Jan 10, 2023

The outstanding tasks are:

  • add note that we modify pep8 to increase the line length
  • add note in the PR review guide that reflowing should only be done as part of other non-stylistic work
  • add text to justify the change someplace in the release notes

@ksunden
Copy link
Member

ksunden commented Jan 25, 2023

I have added notes for each of the highlighted outstanding tasks.

I did not touch MEP8, which is the other place we discuss Matplotlib style outside of release notes as it is my understanding that the MEPs are largely not being used/updated anymore.

@ksunden ksunden marked this pull request as ready for review January 25, 2023 18:56
@tacaswell tacaswell force-pushed the increase_style_linelength branch from 2cd570b to 2061607 Compare January 25, 2023 20:43

The maximum line length for new contributions has been extended from 79 characters to
88 characters.
This change provides an extra 9 characters to allow code which is a single idea to fit
Copy link
Member

Choose a reason for hiding this comment

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

I find the wrapping here is somehow trying to tell me something ;-)

Comment on lines 8 to 11
Other line lengths considered included 115 and 99, but ultimately 88 characters was the
consensus as it is relatively conservative while still providing reasonable benefit.
The ability to view side-by-side git diffs was a key point in choosing the smaller
limit.
Copy link
Member

Choose a reason for hiding this comment

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

On a more serious note, I wonder about putting too much of our back and forth in the API note. Maybe just say we chose 88, its consistent with black, but we may relax further if there is a good reason...

Comment on lines 160 to 164
* Is the change only reflowing code/docstrings for increased line length?
Generally, such changes are discouraged when not part of other non-stylistic
work because it obscures the git history of functional changes to the code.
Reflowing a method or docstring as part of a larger refactor/rewrite is
acceptable.
Copy link
Member

Choose a reason for hiding this comment

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

This seemed a little out of left-field - maybe more general is better?

Suggested change
* Is the change only reflowing code/docstrings for increased line length?
Generally, such changes are discouraged when not part of other non-stylistic
work because it obscures the git history of functional changes to the code.
Reflowing a method or docstring as part of a larger refactor/rewrite is
acceptable.
* Is the change just stylistic? Generally, such changes are discouraged when not
part of other non-stylistic work because it obscures the git history of functional
changes to the code. Style changes to a method or docstring as part of a larger
refactor/rewrite is acceptable.
Suggested change
* Is the change only reflowing code/docstrings for increased line length?
Generally, such changes are discouraged when not part of other non-stylistic
work because it obscures the git history of functional changes to the code.
Reflowing a method or docstring as part of a larger refactor/rewrite is
acceptable.
* Is the change only reflowing code/docstrings for increased line length?
Generally, such changes are discouraged when not part of other non-stylistic
work because it obscures the git history of functional changes to the code.
Reflowing a method or docstring as part of a larger refactor/rewrite is
acceptable.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

This seems good to me. A couple of small suggestions you can take or leave...

@timhoffm timhoffm merged commit 0c8598c into matplotlib:main Jan 26, 2023
@tacaswell tacaswell deleted the increase_style_linelength branch January 26, 2023 21:53
@ksunden ksunden modified the milestones: v3.8.0, v3.7.0 Feb 9, 2023
@ksunden
Copy link
Member

ksunden commented Feb 9, 2023

@meeseeksdev backport to v3.7.0

@lumberbot-app
Copy link

lumberbot-app bot commented Feb 9, 2023

Something went wrong ... Please have a look at my logs.

It seems that the branch you are trying to backport to does not exist.

@ksunden
Copy link
Member

ksunden commented Feb 9, 2023

@meeseeksdev backport to v3.7.x

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.

7 participants