Skip to content
This repository was archived by the owner on May 24, 2021. It is now read-only.

Commit c02c5d8

Browse files
committed
YapfBear: Disable syntax verification
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
1 parent d34239a commit c02c5d8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

bears/python/YapfBear.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def run(self, filename, file,
142142
with prepare_file(options.splitlines(keepends=True),
143143
None) as (file_, fname):
144144
corrected = FormatFile(filename,
145-
style_config=fname)[0].splitlines(True)
145+
style_config=fname,
146+
verify=False)[0].splitlines(True)
146147
diffs = Diff.from_string_arrays(file, corrected).split_diff()
147148
for diff in diffs:
148149
yield Result(self,

tests/python/YapfBearTest.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import sys
12
from queue import Queue
3+
from unittest.case import skipIf
24

35
from bears.python.YapfBear import YapfBear
46
from tests.LocalBearTestHelper import LocalBearTestHelper
@@ -22,6 +24,15 @@ def test_valid(self):
2224
["x = { 'a':37,'b':42,\n", "'c':927}\n", '\n',
2325
"y = 'hello ''world'\n"], valid=False)
2426

27+
def test_valid_python_2(self):
28+
self.check_validity(self.uut, ['print 1\n'], valid=True)
29+
30+
@skipIf(sys.version_info < (3, 5), "ast before 3.5 can't parse async def")
31+
def test_valid_async(self):
32+
self.check_validity(self.uut,
33+
['async def x():\n', ' pass\n'],
34+
valid=True)
35+
2536
def test_blank_line_after_nested_class_or_def(self):
2637
self.section.append(Setting('blank_line_before_nested_class_or_def',
2738
True))

0 commit comments

Comments
 (0)