Skip to content

Commit eaa7bbf

Browse files
committed
Fix invalid soup data
1 parent a68b149 commit eaa7bbf

3 files changed

Lines changed: 8 additions & 10 deletions

File tree

PyMultiDictionary/_dictionary.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def synonym(self, lang: str, word: str, dictionary: str = DICT_EDUCALINGO) -> Sy
257257
elif word == '':
258258
return words
259259

260-
if dictionary == DICT_EDUCALINGO and lang in _EDUCALINGO_LANGS:
260+
elif dictionary == DICT_EDUCALINGO and lang in _EDUCALINGO_LANGS:
261261
bs = self.__search_educalingo(lang, word=word.replace(' ', '-'))
262262
if bs is None:
263263
return words
@@ -409,11 +409,12 @@ def meaning(self, lang: str, word: str, dictionary: str = DICT_EDUCALINGO) -> Me
409409
elif dictionary == DICT_MW and lang == 'en':
410410
if not word.strip():
411411
return {}
412-
soup = self._bsoup(f'https://www.merriam-webster.com/dictionary/{word}')
412+
bs = self._bsoup(f'https://www.merriam-webster.com/dictionary/{word}')
413+
if bs is None:
414+
return {}
413415

414-
definitions = {}
415-
pos_entries = soup.find_all('h2', class_='parts-of-speech')
416-
for pos_tag in pos_entries:
416+
definitions: MeaningType = {}
417+
for pos_tag in bs.find_all('h2', class_='parts-of-speech'):
417418
part_of_speech = pos_tag.get_text(strip=True)
418419

419420
if part_of_speech in definitions:

test/test_dictionary.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,6 @@ def test_antonym(self) -> None:
301301
# Empty
302302
self.assertEqual(d.antonym('en', '!!!'), [])
303303

304-
# Test invalid dictionary
305-
# self.assertRaises(InvalidDictionary, lambda: d.antonym('es', 'word', dictionary=DICT_SYNONYMCOM))
306-
307304
def test_overwrite_cache(self) -> None:
308305
"""
309306
Test request with maxed out cache.

test/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def test_tokenize(self) -> None:
2929
"""
3030
Test tokenize.
3131
"""
32-
s = """
32+
s: str = """
3333
# ----------------------------------------------------------------------
3434
# Settings button
3535
# ----------------------------------------------------------------------
3636
3737
3838
"""
39-
t = []
39+
t: list = []
4040
for w in s.split(' '):
4141
tw = tokenize(w)
4242
if tw == '' or '\n' in tw:

0 commit comments

Comments
 (0)