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

YapfBear: Disable syntax verification #748

Merged
merged 1 commit into from
Aug 31, 2016
Merged

Conversation

underyx
Copy link
Member

@underyx underyx commented Aug 31, 2016

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

@gitmate-bot
Copy link
Collaborator

Comment on 03e0cf4.

Body of HEAD commit contains too long lines.

GitCommitBear, severity NORMAL, section commit.

@@ -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)
Copy link
Contributor

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 ?

Copy link
Member Author

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+")
Copy link
Collaborator

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.

Copy link
Contributor

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

Copy link
Contributor

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)
Copy link
Contributor

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)." ?

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, interesting - alright

@AbdealiLoKo
Copy link
Contributor

ack c02c5d8

1 similar comment
@AbdealiLoKo
Copy link
Contributor

ack c02c5d8

@AbdealiLoKo
Copy link
Contributor

@rultor merge

@rultor
Copy link

rultor commented Aug 31, 2016

@rultor merge

@abdealijk OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit c02c5d8 into coala:master Aug 31, 2016
@rultor
Copy link

rultor commented Aug 31, 2016

@rultor merge

@abdealijk Done! FYI, the full log is here (took me 1min)

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

Successfully merging this pull request may close these issues.

4 participants