One function

_NormalizeCode in google/yapf

The author described this change as Fix verification when there's a comment between decorators.. It counts as a record because the check below fails on the code as it stood at 3756f78ed and passes on 3284b3aad, with nothing else changed between the two runs.

Fix saved2015-03-26
Sharing licenceApache-2.0 · LICENSE
Change size+9 0

What the code was meant to do, written into the code itself as a docstring

Make sure that the code snippet is compilable.

The change

22 """Make sure that the code snippet is compilable."""
33 code = textwrap.dedent(code.lstrip('\n')).lstrip()
44
5+ # Split the code to lines and get rid of all leading full-comment lines as
6+ # they can mess up the normalization attempt.
7+ lines = code.split('\n')
8+ for i, line in enumerate(lines):
9+ line = line.strip()
10+ if line and not line.startswith('#'):
11+ break
12+ code = '\n'.join(lines[i:]) + '\n'
13+
514 if re.match(r'(if|while|for|with|def|class)\b', code):
615 code += '\n pass'
716 elif re.match(r'(elif|else)\b', code):

The check that tells the two apart

failpass·yapftests/reformatter_test.py::SingleLineReformatterTest::testCommentBetweenDecorators

Check file yapftests/reformatter_test.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it3756f78ed1128daaeab0e509085efa13c9a860f2
Broken version dated2015-03-26
Moduleyapf.yapflib.verifier
Units changed_NormalizeCode
Fingerprint1ef8143e89a00384
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in google/yapf