Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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/

like image 472
Samuel Avatar asked Nov 07 '14 19:11

Samuel


People also ask

Does PyCharm follow PEP8?

Tracking PEP8 rules So, as you can see, PyCharm supports PEP8 as the official Python style guide. If you explore the list of inspections ( Ctrl+Alt+S - Inspections), you will see that PyCharm launches the pep8.py tool on your code, and pinpoints the code style violations.

How do I change character limit in PyCharm?

For PyCharm 2018.3 on Windows: File -> Settings ( Ctrl + Alt + S ), then Editor -> Code Style : To follow PEP-8 set Hard wrap at to 80.

Why does Python have a character limit?

Since whitespace has semantic meaning in Python, some methods of word wrapping could produce incorrect or ambiguous results, so there needs to be some limit to avoid those situations.

What is the maximum characters a line can contain in Python?

This immediately brought to mind another character limit that many Python programmers face in their day-to-day lives: the 79-character line limit suggested by Python's PEP8 style guide: Limit all lines to a maximum of 79 characters.


2 Answers

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.

like image 139
munk Avatar answered Sep 22 '22 13:09

munk


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:

  • http://iambigblind.blogspot.com/2013/02/configuring-pep8py-support-in-pycharm-27.html

  • https://intellij-support.jetbrains.com/hc/en-us/community/posts/205816889-Disable-individual-PEP8-style-checking-line-length-

like image 25
Austin Heller Avatar answered Sep 20 '22 13:09

Austin Heller