Skip to content

Commit 08b29e5

Browse files
committed
create_spell_checker function to satisfy flake8
1 parent fa96f4f commit 08b29e5

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

comment_spell_check.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def spell_check_comment(
163163
break
164164

165165
# remove the prefix
166-
wrd = error_word[len(pre) :]
166+
wrd = error_word[len(pre):]
167167
if output_lvl > 1:
168168
print(f"Trying without '{pre}' prefix: {error_word} -> {wrd}")
169169
try:
@@ -412,38 +412,49 @@ def add_dict(enchant_dict, filename, verbose=False):
412412
enchant_dict.add(wrd)
413413

414414

415-
def main():
416-
args = parse_args()
415+
def create_spell_checker(args, output_lvl):
416+
"""Create a SpellChecker."""
417417

418-
sitk_dict = Dict("en_US")
419-
420-
# Set the amount of debugging messages to print.
421-
output_lvl = 1
422-
if args.brief:
423-
output_lvl = 0
424-
else:
425-
if args.verbose:
426-
output_lvl = 2
427-
if args.miss:
428-
output_lvl = -1
418+
my_dict = Dict("en_US")
429419

430420
# Load the dictionary files
431421
#
432422
initial_dct = Path(__file__).parent / "additional_dictionary.txt"
433423
if not initial_dct.exists():
434424
initial_dct = None
435425
else:
436-
add_dict(sitk_dict, str(initial_dct), any([args.brief, output_lvl >= 0]))
426+
add_dict(my_dict, str(initial_dct), any([args.brief, output_lvl >= 0]))
437427

438428
if args.dict is not None:
439429
for d in args.dict:
440-
add_dict(sitk_dict, d, any([args.brief, output_lvl >= 0]))
430+
add_dict(my_dict, d, any([args.brief, output_lvl >= 0]))
441431

432+
# Load the bibliography files
433+
#
442434
if args.bibtex is not None:
443435
for bib in args.bibtex:
444-
bibtex_loader.add_bibtex(sitk_dict, bib, any([args.brief, output_lvl >= 0]))
436+
bibtex_loader.add_bibtex(my_dict, bib, any([args.brief, output_lvl >= 0]))
437+
438+
# Create the SpellChecker
439+
spell_checker = SpellChecker(my_dict, filters=[EmailFilter, URLFilter])
440+
441+
return spell_checker
442+
443+
444+
def main():
445+
args = parse_args()
446+
447+
# Set the amount of debugging messages to print.
448+
output_lvl = 1
449+
if args.brief:
450+
output_lvl = 0
451+
else:
452+
if args.verbose:
453+
output_lvl = 2
454+
if args.miss:
455+
output_lvl = -1
445456

446-
spell_checker = SpellChecker(sitk_dict, filters=[EmailFilter, URLFilter])
457+
spell_checker = create_spell_checker(args, output_lvl)
447458

448459
file_list = []
449460
if len(args.filenames):

0 commit comments

Comments
 (0)