-
Notifications
You must be signed in to change notification settings - Fork 581
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
YapfBear: Disable syntax verification #748
Conversation
Comment on 03e0cf4. Body of HEAD commit contains too long lines. GitCommitBear, severity NORMAL, section |
@@ -142,7 +142,8 @@ def run(self, filename, file, | |||
with prepare_file(options.splitlines(keepends=True), | |||
None) as (file_, fname): | |||
corrected = FormatFile(filename, | |||
style_config=fname)[0].splitlines(True) | |||
style_config=fname, | |||
verify=False)[0].splitlines(True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this was a bug, and a major one - shouldn't there be a test case to avoid regression ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 on it
def test_valid_python_2(self): | ||
self.check_validity(self.uut, ['print 1\n'], valid=True) | ||
|
||
@skipIf(sys.version_info < (3, 5), "async def can't be parsed without 3.5+") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is longer than allowed. (80 > 79)
LineLengthBear, severity NORMAL, section linelength
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also possibly make a test for python 2 syntax please ?
As that was the case mentioned in the issue and that can also be verified for all python versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch. sorry, I didn't see the test above this. nevermind.
Syntax verification is supposed to be a private feature in yapf, used for debugging, but they're still defaulting its flag to True on the public FormatFile function. We need to set it to False to disable syntax error checking in yapf (which seems to be an unmaintained feature of it, since it raises exceptions on async/await and Python 2's print statement), see discussion at google/yapf#293 Fixes coala#738
@@ -22,6 +24,15 @@ def test_valid(self): | |||
["x = { 'a':37,'b':42,\n", "'c':927}\n", '\n', | |||
"y = 'hello ''world'\n"], valid=False) | |||
|
|||
def test_valid_python_2(self): | |||
self.check_validity(self.uut, ['print 1\n'], valid=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come this works ?
Doesnt the documentation say "if you format Python 3 code with YAPF, run YAPF itself under Python 3 (and similarly for Python 2)." ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AbdealiJK I think it's because of this special handling of the old print syntax in python 3:
>>> print 1
File "<stdin>", line 1
print 1
^
SyntaxError: Missing parentheses in call to 'print'
If Python 3 is able to recognize that the syntax is old, then the ast
module must be able to parse this syntax. If the ast
module is able to parse it, I guess it shouldn't fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, interesting - alright
ack c02c5d8 |
1 similar comment
ack c02c5d8 |
@rultor merge |
Syntax verification is supposed to be a private feature in yapf, used for debugging, but they're still defaulting its flag to True on the public FormatFile function. We need to set it to False to disable syntax error checking in yapf (which seems to be an unmaintained feature of it, since it raises exceptions on async/await and py2 print syntax), see discussion at google/yapf#293
Fixes #738
Also filed an upstream issue here google/yapf#297