Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix-ast-source-tran…
Browse files Browse the repository at this point in the history
…slation-issues

# Conflicts:
#	astmonkey/tests/test_visitors.py
#	astmonkey/visitors.py
  • Loading branch information
phihos committed Oct 13, 2018
2 parents 806770a + 14168fe commit 7aaf13c
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions astmonkey/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,26 @@ def _get_current_line_no(self):
lines = len("".join(self.result).split('\n')) if self.result else 0
return lines

@staticmethod
def _get_actual_lineno(node):
@classmethod
def _get_actual_lineno(cls, node):
if node.col_offset == -1 and isinstance(node, (ast.Expr, ast.Str)):
# node is a multi line string and the line number is actually the last line
if isinstance(node, ast.Expr):
str_content = node.value.s
else:
str_content = node.s
if type(str_content) == bytes:
str_content = str_content.decode("utf-8")
str_content = cls._get_string_content(node)
node_lineno = node.lineno - str_content.count('\n')
else:
node_lineno = node.lineno
return node_lineno

@staticmethod
def _get_string_content(node):
# node is a multi line string and the line number is actually the last line
if isinstance(node, ast.Expr):
str_content = node.value.s
else:
str_content = node.s
if type(str_content) == bytes:
str_content = str_content.decode("utf-8")
return str_content

def _newline_needed(self, node):
lines = self._get_current_line_no()
node_lineno = self._get_actual_lineno(node)
Expand Down

0 comments on commit 7aaf13c

Please sign in to comment.