Skip to content

Commit

Permalink
Simplify success exit criteria for detecting language
Browse files Browse the repository at this point in the history
  • Loading branch information
pjkundert committed Dec 14, 2022
1 parent 3f2067d commit 48ccd87
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/mnemonic/mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,10 @@ def detect_language(cls, code: str) -> str:
for word in code.split():
# possible languages have candidate(s) starting with the word/prefix
possible = set(p for p in possible if any(c.startswith( word ) for c in p.wordlist))
if len(possible) == 1:
return possible.pop().language
if not possible:
raise ConfigurationError(f"Language unrecognized for {word!r}")
if len( possible ) < 2:
break
if len(possible) == 1:
return possible.pop().language
raise ConfigurationError(
f"Language ambiguous between {', '.join( p.language for p in possible)}"
)
Expand Down

0 comments on commit 48ccd87

Please sign in to comment.