Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not handle lines broken with "\" well #4

Open
jelle-r opened this issue Feb 3, 2017 · 3 comments
Open

does not handle lines broken with "\" well #4

jelle-r opened this issue Feb 3, 2017 · 3 comments
Labels

Comments

@jelle-r
Copy link

jelle-r commented Feb 3, 2017

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.

@bndr
Copy link
Owner

bndr commented Feb 3, 2017

Thanks for reporting! I'll look into it

@bndr bndr added the bug label Feb 3, 2017
@jelle-r
Copy link
Author

jelle-r commented Feb 3, 2017

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)

@bndr
Copy link
Owner

bndr commented Feb 3, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants