Skip to content

Commit 93e4061

Browse files
authored
Minor updates (#185)
Minor optimization
1 parent 29be829 commit 93e4061

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

spellchecker/spellchecker.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,14 @@ def remove_by_threshold(self, threshold: int = 5) -> None:
509509

510510
def _update_dictionary(self) -> None:
511511
"""Update the word frequency object"""
512-
self._longest_word_length = 0
512+
if not self._dictionary:
513+
self._longest_word_length = 0
514+
self._total_words = 0
515+
self._unique_words = 0
516+
self._letters = set()
517+
return
518+
keys = self._dictionary.keys()
519+
self._longest_word_length = max(map(len, keys))
513520
self._total_words = sum(self._dictionary.values())
514-
self._unique_words = len(self._dictionary.keys())
515-
self._letters = set()
516-
for key in self._dictionary:
517-
if len(key) > self._longest_word_length:
518-
self._longest_word_length = len(key)
519-
self._letters.update(key)
521+
self._unique_words = len(keys)
522+
self._letters = set().union(*keys)

spellchecker/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def decorator_wrapper(func):
2525
def test_inner(*args, **kwargs):
2626
if [int(x) for x in version.split(".")] <= [int(x) for x in __version__.split(".")]:
2727
msg = (
28-
f"The function {func.__name__} must be fully removed as it is depricated"
28+
f"The function {func.__name__} must be fully removed as it is deprecated"
2929
f" and must be removed by version {version}"
3030
)
3131
raise AssertionError(msg)
@@ -76,7 +76,7 @@ def ensure_unicode(value: KeyT, encoding: str = "utf-8") -> str:
7676
if isinstance(value, bytes):
7777
return value.decode(encoding)
7878
elif isinstance(value, list):
79-
raise TypeError(f"The provided value {value} is a not of type str or bytes")
79+
raise TypeError(f"The provided value {value} is not of type str or bytes")
8080
return value
8181

8282

0 commit comments

Comments
 (0)