Use a match statement for PasswordStrength enum values (#4619)

This unblocks the upgrade to mypy 2.2.0, which now flags the
unreachable "return None" statement.
This commit is contained in:
correctmost 2026-07-12 07:20:44 -04:00 committed by GitHub
parent aca482b691
commit 8902d2e310
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 7 deletions

View File

@ -19,14 +19,15 @@ async def get_password(
def password_hint(value: str) -> InputInfo | None: def password_hint(value: str) -> InputInfo | None:
if not value: if not value:
return None return None
strength = PasswordStrength.strength(value) strength = PasswordStrength.strength(value)
if strength in (PasswordStrength.VERY_WEAK, PasswordStrength.WEAK): match strength:
return InputInfo(message=tr('Password strength: Weak'), msg_level=MsgLevelType.MsgError) case PasswordStrength.VERY_WEAK | PasswordStrength.WEAK:
elif strength == PasswordStrength.MODERATE: return InputInfo(message=tr('Password strength: Weak'), msg_level=MsgLevelType.MsgError)
return InputInfo(message=tr('Password strength: Moderate'), msg_level=MsgLevelType.MsgWarning) case PasswordStrength.MODERATE:
elif strength == PasswordStrength.STRONG: return InputInfo(message=tr('Password strength: Moderate'), msg_level=MsgLevelType.MsgWarning)
return InputInfo(message=tr('Password strength: Strong'), msg_level=MsgLevelType.MsgInfo) case PasswordStrength.STRONG:
return None return InputInfo(message=tr('Password strength: Strong'), msg_level=MsgLevelType.MsgInfo)
while True: while True:
result = await Input( result = await Input(