Skip to content

Commit

Permalink
YapfBear: Disable syntax verification
Browse files Browse the repository at this point in the history
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
  • Loading branch information
underyx committed Aug 31, 2016
1 parent d34239a commit c02c5d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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)
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)

@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

0 comments on commit c02c5d8

Please sign in to comment.