Skip to content

Commit

Permalink
Fix regression caused by 664daf3.
Browse files Browse the repository at this point in the history
Pep8ify would crash in certain cases where comments did not have a
previous node.

Closes #17.
  • Loading branch information
spulec committed Jan 21, 2014
1 parent eea4caf commit f581fe1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pep8ify/fixes/fix_whitespace_before_inline_comment.py
Expand Up @@ -9,7 +9,8 @@ def get_previous_node(node):
"""
if node.prev_sibling:
return node.prev_sibling
return get_previous_node(node.parent)
if node.parent:
return get_previous_node(node.parent)


class FixWhitespaceBeforeInlineComment(BaseFix):
Expand All @@ -34,6 +35,9 @@ def match(self, node):
# If the previous node ended in a newline, then this node is
# starting the line so it is not an inline comment.
prev_node = get_previous_node(node)
if not prev_node:
# If no previous node, this is not an inline comment.
return False
prev_node_text = node_text(prev_node)
if prev_node_text.endswith('\n'):
return False
Expand Down
@@ -1,3 +1,5 @@
# comment 1
# comment 2
import baz

baz.bar(
Expand Down
@@ -1,3 +1,5 @@
# comment 1
# comment 2
import baz

baz.bar(
Expand Down

0 comments on commit f581fe1

Please sign in to comment.