Some Python style nits.

This commit is contained in:
Georg Brandl 2016-05-27 15:57:03 +02:00
parent 9110b6eb60
commit f314fa8d28

View File

@ -58,9 +58,9 @@ def collect(lints, deprecated_lints, restriction_lints, fn):
# remove \-newline escapes from description string # remove \-newline escapes from description string
desc = nl_escape_re.sub('', match.group('desc')) desc = nl_escape_re.sub('', match.group('desc'))
restriction_lints.append((os.path.splitext(os.path.basename(fn))[0], restriction_lints.append((os.path.splitext(os.path.basename(fn))[0],
match.group('name').lower(), match.group('name').lower(),
"allow", "allow",
desc.replace('\\"', '"'))) desc.replace('\\"', '"')))
def gen_table(lints, link=None): def gen_table(lints, link=None):
@ -100,6 +100,7 @@ def gen_deprecated(lints):
for lint in lints: for lint in lints:
yield ' store.register_removed("%s", "%s");\n' % (lint[1], lint[2]) yield ' store.register_removed("%s", "%s");\n' % (lint[1], lint[2])
def replace_region(fn, region_start, region_end, callback, def replace_region(fn, region_start, region_end, callback,
replace_start=True, write_back=True): replace_start=True, write_back=True):
"""Replace a region in a file delimited by two lines matching regexes. """Replace a region in a file delimited by two lines matching regexes.
@ -168,8 +169,8 @@ def main(print_only=False, check=False):
changed |= replace_region( changed |= replace_region(
'README.md', 'README.md',
r'^There are \d+ lints included in this crate:', "", r'^There are \d+ lints included in this crate:', "",
lambda: ['There are %d lints included in this crate:\n' % (len(lints) lambda: ['There are %d lints included in this crate:\n' %
+ len(restriction_lints))], (len(lints) + len(restriction_lints))],
write_back=not check) write_back=not check)
# update the links in the CHANGELOG # update the links in the CHANGELOG
@ -196,10 +197,10 @@ def main(print_only=False, check=False):
# same for "deprecated" lint collection # same for "deprecated" lint collection
changed |= replace_region( changed |= replace_region(
'clippy_lints/src/lib.rs', r'let mut store', r'end deprecated lints', 'clippy_lints/src/lib.rs', r'let mut store', r'end deprecated lints',
lambda: gen_deprecated(deprecated_lints), lambda: gen_deprecated(deprecated_lints),
replace_start=False, replace_start=False,
write_back=not check) write_back=not check)
# same for "clippy_pedantic" lint collection # same for "clippy_pedantic" lint collection
changed |= replace_region( changed |= replace_region(