-
Notifications
You must be signed in to change notification settings - Fork 291
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
IndexError: string index out of range #346
Comments
I managed to fix this issue. Somewhat of a stopgap solution, because I did not look too deep into why this was occurring (also because I am unsure if From 7f25de9b5eae80d8ce7cb5df8af233e17bb60775 Mon Sep 17 00:00:00 2001
From: Chris Tarazi <tarazichris@gmail.com>
Date: Mon, 18 Sep 2017 11:55:23 -0700
Subject: [PATCH 1/1] Fix issue #346: avoid IndexError on empty line
---
autopep8.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/autopep8.py b/autopep8.py
index 918af2d..f79ad71 100755
--- a/autopep8.py
+++ b/autopep8.py
@@ -3520,6 +3520,10 @@ def line_shortening_rank(candidate, indent_word, max_line_length,
rank = 0
lines = candidate.rstrip().split('\n')
+ # Avoid IndexError -- first line may be empty.
+ if not lines[0].rstrip():
+ return rank
+
offset = 0
if (
not lines[0].lstrip().startswith('#') and
--
2.14.1 |
A code example would be helpful us. Thanks! |
I have the same problem with this chunk of code: def something:
pass
# a quick brown fox jumps over the lazy dog, again, again, again, again, again..
something_else = 123 The comment is the line that triggers the problem. |
Can confirm @pikacic example triggers the problem. Seems like a very long comment that comes after a line that requires indentation is what causes it. |
I can't reproduce the
--- original/foo.py
+++ fixed/foo.py
@@ -1,5 +1,8 @@
def something():
pass
-# a quick brown fox jumps over the lazy dog, again, again, again, again, again..
+
+# # a quick brown fox jumps over the lazy dog, again, again, again,
+
+# again, again..
something_else = 123 |
@fcastilloec |
@hhatto I just updated to v1.3.3 and I don't see the error anymore! Thanks so much! |
I'm trying to run
autopep8
on my file and this is the output I get:I've tried to look everywhere what's going on, but I haven't found any answers.
Here's the version of my packages:
autopep8 1.3.2 (pycodestyle: 2.3.1)
pep8 1.7.0
I'm using Ubuntu 16.04, and as the versions show, I install the packages using
pip
The text was updated successfully, but these errors were encountered: