Skip to content

Commit 3a22cca

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 #738
1 parent d34239a commit 3a22cca

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-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

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ def test_valid(self):
2222
["x = { 'a':37,'b':42,\n", "'c':927}\n", '\n',
2323
"y = 'hello ''world'\n"], valid=False)
2424

25+
def test_valid_python_2(self):
26+
self.check_validity(self.uut, ['print 1\n'], valid=True)
27+
28+
def test_valid_async(self):
29+
self.check_validity(self.uut,
30+
['async def x():\n', ' pass\n'],
31+
valid=True)
32+
2533
def test_blank_line_after_nested_class_or_def(self):
2634
self.section.append(Setting('blank_line_before_nested_class_or_def',
2735
True))

0 commit comments

Comments
 (0)