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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bears/python/YapfBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

diffs = Diff.from_string_arrays(file, corrected).split_diff()
for diff in diffs:
yield Result(self,
Expand Down
11 changes: 11 additions & 0 deletions tests/python/YapfBearTest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import sys
from queue import Queue
from unittest.case import skipIf

from bears.python.YapfBear import YapfBear
from tests.LocalBearTestHelper import LocalBearTestHelper
Expand All @@ -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


@skipIf(sys.version_info < (3, 5), "ast before 3.5 can't parse async def")
def test_valid_async(self):
self.check_validity(self.uut,
['async def x():\n', ' pass\n'],
valid=True)

def test_blank_line_after_nested_class_or_def(self):
self.section.append(Setting('blank_line_before_nested_class_or_def',
True))
Expand Down