Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/_pytest/_code/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ def get_statement_startend2(lineno, node):

def getstatementrange_ast(lineno, source, assertion=False, astnode=None):
if astnode is None:
content = str(source)
if six.PY2:
content = unicode(source)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this still might fail, because unicode will try to use the ascii codec to decode the bytestream (see py27 failure). Not sure if by this point getstatementrange_ast shouldn't already be a unicode stream actually. 🤔

else:
content = str(source)
astnode = compile(content, "source", "exec", 1024) # 1024 for AST

start, end = get_statement_startend2(lineno, astnode)
Expand Down