[Python-ideas] PEP 8 update on line length

Raymond Hettinger raymond.hettinger at gmail.com
Thu Feb 21 14:59:56 EST 2019


On Feb 18, 2019, at 8:37 PM, Simon <simon.bordeyne at gmail.com> wrote:
> 
> I'd like to propose an update to PEP8. Indeed, the 80 characters per line guideline is, I feel, outdated.

I concur.  We now put expressions in f-strings and have assignment expressions that easily spill over 80 characters if one uses all but the most compact variable names.  Comprehensions tend to make expressions longer.  Queries and filters in Pandas also easily spill over.  The 80 character limit pre-dates these evolutions of the language.

In particular, the case where I most want to let people run with long lines is in forming messages to be displayed to a user.  Templates can get fat even if the displayed message is not long.  The code is more readable if people don't mangle their templates with line wrapping.

class Frabawidget:
    ...
    @wozzle.setter
    def (self, woozle):
        if not (self.min_woozle < woozle < self.max_woozle):
            raise ValueError(f"Expected woozle to be between {self.min_woozle} and {self.max_woozle}")
        self._wozzle = normalize(woozle)
        
In doing code reviews, I see many fewer atrocities from long lines than I do from weird line-wraps and from variable names that have been over-shortened to make the line fit in 80 characters.  To avoid these issues, my clients typically set their line limits at 90 or 100 (though I have one customer that keeps 80 characters but uses two-space indents, yuck).

PEP 8 is mostly about readability.  However, the line length limit often seems to cause less readable code.


Raymond


More information about the Python-ideas mailing list