Why does PyCharm use 120 Character Lines even though PEP8 Specifies 79?

PythonPycharmPep8

Python Problem Overview


PEP8 clearly specifies 79 characters, however, PyCharm defaults to 120 and gives me the warning "PEP8: line too long (... > 120 characters)".

Did previous versions of PEP8 use 120 and PyCharm not update its PEP8 checker? I couldn't find any previous versions of the PEP8 Guide, however, I can easily find previous version of the PEP8 Python scripts.

I'm starting a new Python project and I'm not sure which to use.

References:

http://legacy.python.org/dev/peps/pep-0008/

Python Solutions


Solution 1 - Python

PyCharm is built on top of IntelliJ. IntelliJ has a default line length of 120 characters.

This is probably because you can't fit a common Java name like: @annotated public static MyObjectFactoryFactory enterpriseObjectFactoryFactoryBuilderPattern { in a mere 80 character line. (I'm poking fun, but Java names do tend to be longer by convention).

The pep8 checker is configurable, so you can specify a better max line length - like 79 characters.

The error is misleading because the pep8 checker formats the text with something like "PEP8: line too long(... > %s characters)" % max_line_setting. So it's using the pep8 checker, with a specific configuration, not claiming that pep8 specifies a 120 character line.

Solution 2 - Python

If you want to remove the limit warning altogether you can take the following steps:

  1. In PyCharm, click File > Settings
  2. In the project settings section, click Editor > Inspections
  3. In the list that appears, expand Python
  4. Under Python, scroll down and click "PEP8 coding style violation"
  5. Click the + button next to "Ignore errors" in the bottom right
  6. Type out E501 and click Apply and/or OK

Sources:

Solution 3 - Python

AFAIK, PEP8 has never allowed 120 characters, but not everyone follows PEP8. To answer your question: stay under 80 characters, both from common courtesy and good sense.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSamuelView Question on Stackoverflow
Solution 1 - PythonmunkView Answer on Stackoverflow
Solution 2 - PythonAustin HellerView Answer on Stackoverflow
Solution 3 - PythonJon KiparskyView Answer on Stackoverflow