Done with the following script, reverting false positives in
several files triggered by missing docstrings which the script
does not consider:
import sys
def fix(lines):
answer = []
post_def = False
for line in lines:
if line.lstrip().startswith(("def ", "class ")):
# print(line.rstrip())
post_def = True
if post_def and line.lstrip().startswith('"""'):
post_def = False
# Looks like line one of a docstring
if line.rstrip().endswith('"""'):
# a one-liner
if line.rstrip().endswith('."""'):
# good
pass
elif line.rstrip().endswith(('?"""', '!"""')):
# ugly
pass
else:
print(line.rstrip())
line = line.rstrip()[:-3] + '."""\n'
else:
# multi-liner
if line.rstrip().endswith('.'):
# good
pass
elif line.rstrip().endswith(('?', '!')):
# ugly
pass
else:
print(line.rstrip())
line = line.rstrip() + ".\n"
answer.append(line)
return answer
for f in sys.argv[1:]:
print(f)
with open(f) as handle:
old = list(handle)
new = fix(old)
with open(f, "w") as handle:
for line in new:
handle.write(line)
print("Done")