Skip to content

Commit e8befc1

Browse files
Simplify code
The list comprehension is shorter than the map() version. I feel it is also simpler, although that is debatable. This is consistent with the previous commit.
1 parent fd75e95 commit e8befc1

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

codespell_lib/_codespell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ def ask_for_word_fix(line, wrongword, misspelling, interactivity):
528528
# we ask the user which word to use
529529

530530
r = ''
531-
opt = list(map(lambda x: x.strip(), misspelling.data.split(',')))
531+
opt = [w.strip() for w in misspelling.data.split(',')]
532532
while not r:
533533
print("%s Choose an option (blank for none): " % line, end='')
534534
for i in range(len(opt)):

codespell_lib/tests/test_basic.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,14 @@ def test_case_handling(tmpdir, capsys):
393393
assert f.read().decode('utf-8') == 'this has an ASCII error'
394394

395395

396-
def test_case_handling_in_fixes(tmpdir, capsys):
397-
"""Test that the case of fixes is similar to the mispelled word."""
396+
def _helper_test_case_handling_in_fixes(tmpdir, capsys, reason):
398397
d = str(tmpdir)
399-
with open(op.join(d, 'dictionary_with_reason.txt'), 'w') as f:
400-
fix = 'adopter, adaptor'
401-
reason = 'these are different words!'
402-
f.write(f'adoptor->{fix}, {reason}\n')
398+
399+
with open(op.join(d, 'dictionary.txt'), 'w') as f:
400+
if reason:
401+
f.write('adoptor->adopter, adaptor, reason\n')
402+
else:
403+
f.write('adoptor->adopter, adaptor,\n')
403404
dictionary_name = f.name
404405

405406
# the mispelled word is entirely lowercase
@@ -408,33 +409,45 @@ def test_case_handling_in_fixes(tmpdir, capsys):
408409
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
409410
# all suggested fixes must be lowercase too
410411
assert 'adopter, adaptor' in stdout
412+
# the reason, if any, must not be modified
413+
if reason:
414+
assert 'reason' in stdout
411415

412416
# the mispelled word is capitalized
413417
with open(op.join(d, 'bad.txt'), 'w') as f:
414418
f.write('Early Adoptor\n')
415419
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
416420
# all suggested fixes must be capitalized too
417421
assert 'Adopter, Adaptor' in stdout
418-
# the reason, however, must not be modified
419-
assert reason in stdout
422+
# the reason, if any, must not be modified
423+
if reason:
424+
assert 'reason' in stdout
420425

421426
# the mispelled word is entirely uppercase
422427
with open(op.join(d, 'bad.txt'), 'w') as f:
423428
f.write('EARLY ADOPTOR\n')
424429
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
425430
# all suggested fixes must be uppercase too
426431
assert 'ADOPTER, ADAPTOR' in stdout
427-
# the reason, however, must not be modified
428-
assert reason in stdout
432+
# the reason, if any, must not be modified
433+
if reason:
434+
assert 'reason' in stdout
429435

430436
# the mispelled word mixes lowercase and uppercase
431437
with open(op.join(d, 'bad.txt'), 'w') as f:
432438
f.write('EaRlY AdOpToR\n')
433439
code, stdout, _ = cs.main('-D', dictionary_name, f.name, std=True)
434440
# all suggested fixes should be lowercase
435441
assert 'adopter, adaptor' in stdout
436-
# the reason, however, must not be modified
437-
assert reason in stdout
442+
# the reason, if any, must not be modified
443+
if reason:
444+
assert 'reason' in stdout
445+
446+
447+
def test_case_handling_in_fixes(tmpdir, capsys):
448+
"""Test that the case of fixes is similar to the mispelled word."""
449+
_helper_test_case_handling_in_fixes(tmpdir, capsys, reason=False)
450+
_helper_test_case_handling_in_fixes(tmpdir, capsys, reason=True)
438451

439452

440453
def test_context(tmpdir, capsys):

0 commit comments

Comments
 (0)