Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when parsing long comment (E501) #333

movermeyer opened this issue Jun 26, 2017 · 1 comment · Fixed by #334

Crash when parsing long comment (E501) #333

movermeyer opened this issue Jun 26, 2017 · 1 comment · Fixed by #334


Copy link

movermeyer commented Jun 26, 2017

When a ran autopep8 over a large codebase, I noticed one file that was causing it to crash.

It seems to only happen in specific cases. This is what I had to have in my Python file in to get it to trigger:

  1. A function
  2. A single empty line
  3. A long comment (long enough to trigger E501, 80 characters in my case)
  4. A variable assignment

Example code:

def foo(bar):

#This is a long comment. It has more than 80 characters in it. It triggers an E501
baz = []

Which gives the following stack trace:

$> env/bin/autopep8
Traceback (most recent call last):
  File "env/bin/autopep8", line 11, in <module>
  File "env/lib/python2.7/site-packages/", line 3811, in main
    fix_multiple_files(args.files, args, sys.stdout)
  File "env/lib/python2.7/site-packages/", line 3723, in fix_multiple_files
    _fix_file((name, options, output))
  File "env/lib/python2.7/site-packages/", line 3704, in _fix_file
  File "env/lib/python2.7/site-packages/", line 3104, in fix_file
    fixed_source = fix_lines(fixed_source, options, filename=filename)
  File "env/lib/python2.7/site-packages/", line 3084, in fix_lines
    fixed_source = fix.fix()
  File "env/lib/python2.7/site-packages/", line 564, in fix
  File "env/lib/python2.7/site-packages/", line 507, in _fix_source
    modified_lines = fix(result)
  File "env/lib/python2.7/site-packages/", line 872, in fix_long_line_physically
  File "env/lib/python2.7/site-packages/", line 903, in fix_long_line
  File "env/lib/python2.7/site-packages/", line 1166, in get_fixed_long_line
    key=lambda x: line_shortening_rank(
  File "env/lib/python2.7/site-packages/", line 1170, in <lambda>
  File "env/lib/python2.7/site-packages/", line 3465, in line_shortening_rank
    lines[0].rstrip()[-1] not in '([{'
IndexError: string index out of range

Adding the --ignore=E501 flag makes it work again.

Tested with:

  • cPython 2.7.5 (on CentOS 7) and cPython 2.7.13 (on Windows 10)
  • autopep8 1.3.2 (pycodestyle: 2.3.1)
@myint myint added the bug label Jun 27, 2017
myint added a commit that referenced this issue Jun 27, 2017
This fixes #333. The bug was introduced in 138f281.
Copy link

myint commented Jun 27, 2017

Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging a pull request may close this issue.

2 participants