From 41dc513f0d42cbb39ab02861b9bb2ba8dd3a0174 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 28 Jul 2023 16:16:03 +0200 Subject: [PATCH] Simpler code for parsing dictionaries --- codespell_lib/_codespell.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 19999cdbd6e..800e12c9947 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -637,19 +637,14 @@ def build_dict( if key in ignore_words: continue data = data.strip() - fix = data.rfind(",") - if fix < 0: - fix = True - reason = "" - elif fix == (len(data) - 1): - data = data[:fix] - reason = "" + if "," in data: fix = False + data, reason = data.rsplit(",", 1) + reason = reason.lstrip() else: - reason = data[fix + 1 :].strip() - data = data[:fix] - fix = False + fix = True + reason = "" misspellings[key] = Misspelling(data, fix, reason)