diff --git a/src/mnemonic/mnemonic.py b/src/mnemonic/mnemonic.py index 008dbc3..4e821a0 100644 --- a/src/mnemonic/mnemonic.py +++ b/src/mnemonic/mnemonic.py @@ -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)}" )