57

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/

Samuel
  • 8,063
  • 8
  • 45
  • 41

3 Answers3

65

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.

BiBi
  • 7,418
  • 5
  • 43
  • 69
munk
  • 12,340
  • 8
  • 51
  • 71
  • I think Intellij Python plugin IS Pycharm for Intellij. But I wouldn't say that Pycharm is built on top of Intellij, which is the highend product from JetBrains. – DevLounge Nov 10 '14 at 17:46
  • 2
    @Apero According to the [JetBrains blog](http://blog.jetbrains.com/pycharm/2013/10/pycharm-3-0-community-edition-source-code-now-available/) "The code is all there on GitHub, ready for you to play with. It’s not a separate project but rather part of the main IntelliJ IDEA Community Edition project". IntelliJ is just their Java IDE, and comes in both a free-as-in-beer community edition and a paid version with additional enterprisey features. You can purchase a version of PyCharm with similar features as well. – munk Nov 10 '14 at 18:58
  • 3
    This is a known issue they are working to correct: https://youtrack.jetbrains.com/issue/PY-16078 – phoenix Aug 03 '15 at 20:59
7

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:

Austin Heller
  • 171
  • 1
  • 9
  • Ignoring this PEP8 violation however, is generally bad practice as it can mean your code is less readable in most circumstances. – AJ123 Feb 01 '23 at 22:39
-3

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.

Jon Kiparsky
  • 7,499
  • 2
  • 23
  • 38
  • 7
    But PyCharm claims 120 is PEP8. Why are they misleading people? – Samuel Nov 07 '14 at 19:38
  • 4
    I'll defer to @munkhd's answer, since I don't use PyCharm. (stick with emacs, everything will work much better...) – Jon Kiparsky Nov 07 '14 at 19:39
  • 2
    From PEP-8 (but I code up to 120 chars, and occasionally violate that limit too): "... Some teams strongly prefer a longer line length. For code maintained exclusively or primarily by a team that can reach agreement on this issue, it is okay to increase the **line length limit up to 99 characters** ..." – NeilG Jul 26 '19 at 00:13