Skip to content

Commit

Permalink
[spelling chacker] Better variable name in the Spelling checker
Browse files Browse the repository at this point in the history
Following a failed attempt to add functional tests for spelling checker in pylint-dev#6137
  • Loading branch information
Pierre-Sassoulas committed Feb 24, 2023
1 parent 8bf1120 commit 774b736
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pylint/checkers/spelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
WikiWordFilter,
get_tokenizer,
)

PYENCHANT_AVAILABLE = True
except ImportError:
enchant = None
PYENCHANT_AVAILABLE = False

class EmailFilter: # type: ignore[no-redef]
...
Expand All @@ -62,17 +65,16 @@ def get_tokenizer(
return Filter()


if enchant is not None:
br = enchant.Broker()
dicts = br.list_dicts()
dict_choices = [""] + [d[0] for d in dicts]
dicts = [f"{d[0]} ({d[1].name})" for d in dicts]
dicts = ", ".join(dicts)
instr = ""
ENCHANT_INSTRUCTION = "To make it work, install the 'python-enchant' package."
if PYENCHANT_AVAILABLE:
broker = enchant.Broker()
enchant_dicts = broker.list_dicts()
enchant_dict_choices = [""] + [d[0] for d in enchant_dicts]
enchant_dicts = [f"{d[0]} ({d[1].name})" for d in enchant_dicts]
enchant_dicts = ", ".join(enchant_dicts)
else:
dicts = "none"
dict_choices = [""]
instr = " To make it work, install the 'python-enchant' package."
enchant_dicts = "none"
enchant_dict_choices = [""]


class WordsWithDigitsFilter(Filter): # type: ignore[misc]
Expand Down Expand Up @@ -237,9 +239,9 @@ class SpellingChecker(BaseTokenChecker):
"default": "",
"type": "choice",
"metavar": "<dict name>",
"choices": dict_choices,
"choices": enchant_dict_choices,
"help": "Spelling dictionary name. "
f"Available dictionaries: {dicts}.{instr}",
f"Available dictionaries: {enchant_dicts}. {ENCHANT_INSTRUCTION}",
},
),
(
Expand Down

0 comments on commit 774b736

Please sign in to comment.