From 07a4be4f0221b379efce28ed60717aed3ebdc62a Mon Sep 17 00:00:00 2001 From: Perry Kundert Date: Wed, 14 Dec 2022 08:25:57 -0800 Subject: [PATCH] Simplify success exit criteria for detecting language --- src/mnemonic/mnemonic.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/mnemonic/mnemonic.py b/src/mnemonic/mnemonic.py index e64921d..05db998 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)}" )