Line lengths in Python

22 views
Skip to first unread message

Bruce Dawson

unread,
Sep 26, 2023, 3:01:13 PM9/26/23
to python
Chromium has a couple of deviations from PEP-8 as documented here. I knew that we were supposed to be moving towards four-character indents, but I didn't know that 79-character line lengths were also a goal, at least for new scripts.

This came up because a recent change reformatted some comment lines from 80 to 79 characters, and I objected to the change because it went against what our presubmits and code formatter enforce.

In response this CL was created and I wanted to run it by the Python discussion group. This change gets our presubmit system to warn on 80-character lines for Python, instead of 81 character lines:

crrev.com/c/4886040

This will cause a lot of noise on Python changes, and without the formatting tool also being adjusted it might be messy to make the updates. On the other hand, staying with 80-character lines forever while saying "we should really do 79-character lines" also seems messy.

Thoughts?

--
Bruce Dawson, he/him

Mike Frysinger

unread,
Sep 26, 2023, 3:07:43 PM9/26/23
to Bruce Dawson, python
personally i think we should go with 80 and update the docs

but regardless of what we pick, .style.yapf needs to be in sync
-mike

--
You received this message because you are subscribed to the Google Groups "python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python+un...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/python/CAE5mQiMbdPdET8t_HQvpL5zEnQB_G5vL%3Dr7zKMHam3txNcq4kA%40mail.gmail.com.

Dirk Pranke

unread,
Sep 26, 2023, 3:33:35 PM9/26/23
to Mike Frysinger, Bruce Dawson, python
Hm. I didn't realize (or I forgot) that PEP-8 wanted 79 characters. I suppose I would vote to follow PEP-8, because I don't see a compelling reason not to do so, but I don't feel strongly about it. As with Mike, I feel more strongly that our formatter (and pylint) should enforce whatever we say we follow.

-- Dirk

K. Moon

unread,
Sep 26, 2023, 3:49:27 PM9/26/23
to Dirk Pranke, Mike Frysinger, Bruce Dawson, python
I was reading PEP 8 recently, and there's actually a separate, shorter line length of 72 for "flowing long blocks of text with fewer structural restrictions (docstrings or comments)".

I doubt anyone would be bothered by sticking with 79/80 characters for comments, but formatters might be more opinionated.

Mike Frysinger

unread,
Sep 28, 2023, 3:35:44 AM9/28/23
to Dirk Pranke, Bruce Dawson, python

Andrew Grieve

unread,
Sep 28, 2023, 9:21:50 AM9/28/23
to Mike Frysinger, Dirk Pranke, Bruce Dawson, python
I think it's fairly impractical to reformat all of our Python as PEP-8, which is why the docs were say that new code should follow it. A presubmit that applies to all code wouldn't make sense though. Let's leave it to the auto-formatters.

Mike Frysinger

unread,
Sep 28, 2023, 10:08:33 AM9/28/23
to Andrew Grieve, Dirk Pranke, Bruce Dawson, python
we reformatted depot_tools with pep8/80 cols with yapf fwiw.
-mike 
Reply all
Reply to author
Forward
0 new messages