[Python-ideas] PEP 8 update on line length

Samuel Colvin S at muelcolvin.com
Tue Feb 19 09:28:57 EST 2019


I too would argue that it's time to reconsider line length limits.

But the reason is not monitor changes, or any particularly strong personal
opinion, but changes to python:

Let's take a real life example from here
<https://github.com/samuelcolvin/pydantic/blob/master/pydantic/utils.py#L246>
(changed
very slightly for this example), in tranitional python the signature might
be:

def resolve_annotations(raw_annotations, module_name):

55 characters, all fine. Now let's look at that same function in modern
python with type hints:

def resolve_annotations(*, raw_annotations: Dict[str, Type[Any]],
module_name: Optional[str]) -> Dict[str, Type[Any]]:

119 characters! No daft 5-word variable names, just a clean (if strict)
function definition. I don't see how anyone can say that would be more
readable with a 80 character line limit. And that's not even an extreme
case, we don't have lots of "Optional[..]" or "Tuple[ThingA, ThingB,
ThingC]".

Type hints (for good or bad depending on your view point) have made python
code more verbose, that's just a fact. Code that used to fit on one line
with 80char limit now require 120 (or more), therefore in my opinion the
recommendation should change to keep up with changes in python.

My preference is 120 characters (that's also the default in pycharm I
believe). It works well on a desktop monitor, leaving room for a file
browser and part of another window, it's also fine on a 13" laptop screen.

Then again, every IDE and linter I've used (even black) allows the line
length to be varried, so this is only really a problem in the standard
library and libraries which adhere closely to pep8.

Samuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190219/6166c6e3/attachment.html>


More information about the Python-ideas mailing list