-
Notifications
You must be signed in to change notification settings - Fork 99
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
Refactoring Python 2.7 files does not work (parse error on print statement) #119
Comments
Oh right, I have seen this earlier issue #60 Firstly the docs change seems insufficient, it shouldn't advertise Python 2 support anywhere without mentioning this important caveat. Secondly, if this is the reason:
...it seems like it would be better to make this an option at the user level and just explain the problem - maybe I know all my py2 files use print statements rather than "parenthesised print statements without an explicit future import" in which case I'm fine to run with the other grammar |
I mean... the behaviour without this forced option seems correct to me if I comment it out I can parse: if __name__ == "__main__":
print "Python 2 print statement"
print("parenthesised print statement") If I add a print function with kwarg: if __name__ == "__main__":
print "Python 2 print statement"
print("parenthesised print statement")
print("print function with kwarg", end="") it fails with parse error on the last line (but it should right? this is invalid python 2 - if I run the file in an interpreter I get a SyntaxError from this line) then if I add the future import: from __future__ import print_function
def main():
print "Python 2 print statement"
print("parenthesised print statement")
print("print function with kwarg", end="") I get parse error from the print statement instead... But I should, because a python 2.7 interpreter gives a SyntaxError on this line. Finally removing the print statement and keeping the future import, no errors as expected. So I don't understand what you're trying to work around, it seems like fissix already does the right thing here? Is it that Python 3 files are handled wrongly? I guess they're auto-detected as python 2 because they lack the future import, and then print functions with kwarg will error. But in that case it seems again like the right thing to do would be expose it as a user option - I am unlikely to be refactoring a mix of py2 and p3 files in the same run. And as long as we don't mix files of different versions I can set the option I want (forced print function grammar for py3, auto-detect for py2) and everything will work correctly. |
I think the intent was to parse I would accept a pull request that adds such an option to |
great I'll send one, thanks :) |
https://pybowler.io/docs/basics-intro
Everything was working fine until I tried running on a (Py 2.7) source file which had a print statement in it
Then I get:
After putting some breakpoints in and digging through the source it seems the problem is here:
Bowler/bowler/tool.py
Line 98 in 195fbae
BowlerTool
hard-codes it so that the underlying fissixRefactorTool
will use the no-print-statements grammar, which is therefore not Python 2 compatible.Commenting out that line fixes it for me... I wonder why it was added?
The text was updated successfully, but these errors were encountered: