pycycle
pycycle copied to clipboard
does not handle lines broken with "\" well
trafficstars
I get parse errors on python code with lines broken with a backslash character like:
assert True, \
"This is valid python, right?"
It gives output:
Parsing of file failed: valid.py
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pycycle/utils.py", line 70, in read_project
tree = ast.parse('\n'.join(lines))
File "/usr/lib/python2.7/ast.py", line 37, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 2
^
SyntaxError: invalid syntax
Expected:
Also python code with backslash ending lines is parsed correctly.
Thanks for reporting! I'll look into it
This seems to fix it (utils.py):
- lines = f.readlines()
- tree = ast.parse('\n'.join(lines))
+ file_data = f.read()
+ lines = file_data.splitlines()
+ tree = ast.parse(file_data)
can you submit a pull request, so I can directly merge it?