Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@alxwrd
Copy link
Member

@alxwrd alxwrd commented Jul 22, 2025

This adds an additional KeyError catch when trying to get a word from cmudict as the latest release of python-cmudict removed the defaultdict.

alxwrd added 2 commits July 22, 2025 09:31
latest release of cmudict means that

```python
import textstat

textstat.count_syllables("text_a")
```

causes the error

```python
  File "textstat/backend/counts/_count_syllables.py", line 30, in count_syllables
    cmu_phones = cmu_dict[word][0]
KeyError: 'text_a'
```
fixes #212

in latest python-cmudict, the dict of syllables is no longer a default
dict, so now raises a KeyError
@alxwrd alxwrd linked an issue Jul 22, 2025 that may be closed by this pull request
1 task
@alxwrd
Copy link
Member Author

alxwrd commented Jul 22, 2025

$ uv run --with git+https://github.com/textstat/textstat.git@main python -c "import textstat; print(textstat.flesch_kincaid_grade('text_a'))" --python=3.10 --isolated --no-project

textstat/backend/counts/_count_syllables.py", line 30, in count_syllables
    cmu_phones = cmu_dict[word][0]
KeyError: 'text_a'

$ uv run --with git+https://github.com/textstat/textstat.git@cmu-fix python -c "import textstat; print(textstat.flesch_kincaid_grade('text_a'))" --python=3.10 --isolated --no-project

8.400000000000002

@alxwrd alxwrd merged commit 92af1c5 into main Jul 22, 2025
6 checks passed
@alxwrd alxwrd deleted the cmu-fix branch July 22, 2025 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Key Error in flesch_kincaid_grade

2 participants