Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
to_entropy()looks up each word's index withlist.index():list.index()never returns a negative value — when the element isnot found, it raises
ValueErrordirectly instead of returning-1.As a result, the
if ndx < 0branch is unreachable: it can never betrue, because if the word isn't in the wordlist the exception is
already raised two lines earlier, before the check even runs.
Impact
When an invalid/misspelled word is passed to
to_entropy(), callersget a raw
ValueErrorwith Python's generic list-lookup message(e.g.
'notaword' is not in list) instead of the intended,descriptive
LookupError(Unable to find "notaword" in word list.). This is misleading for end users debugging a bad mnemonic,and breaks any caller that specifically catches
LookupError(matching how the rest of this library reports lookup failures)
without also catching
ValueError.Reproduction
Fix
Wrap the
.index()call in atry/except ValueErrorand raise theintended
LookupErrorfrom there, instead of checking a conditionthat can never be true:
Testing
a raw
ValueErrorwas raised instead ofLookupError.LookupError: Unable to find "notaword" in word list.is nowraised as intended.
pytest tests/) before andafter the change: all 7 tests pass in both cases, confirming no
regression to existing checksum/entropy behavior.
This is a pure error-handling fix; the entropy/checksum computation
logic is unchanged.