pycycle icon indicating copy to clipboard operation
pycycle copied to clipboard

does not handle lines broken with "\" well

Open jelle-r opened this issue 8 years ago • 3 comments
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.

jelle-r avatar Feb 03 '17 10:02 jelle-r

Thanks for reporting! I'll look into it

bndr avatar Feb 03 '17 10:02 bndr

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)

jelle-r avatar Feb 03 '17 10:02 jelle-r

can you submit a pull request, so I can directly merge it?

bndr avatar Feb 03 '17 10:02 bndr