From 48ccd8736e3ae40e59766b9da412299074d9d4fb 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 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)}" )