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:
if not value:
return None
strength = PasswordStrength.strength(value)
if strength in (PasswordStrength.VERY_WEAK, PasswordStrength.WEAK):
return InputInfo(message=tr('Password strength: Weak'), msg_level=MsgLevelType.MsgError)
elif strength == PasswordStrength.MODERATE:
return InputInfo(message=tr('Password strength: Moderate'), msg_level=MsgLevelType.MsgWarning)
elif strength == PasswordStrength.STRONG:
return InputInfo(message=tr('Password strength: Strong'), msg_level=MsgLevelType.MsgInfo)
return None
match strength:
case PasswordStrength.VERY_WEAK | PasswordStrength.WEAK:
return InputInfo(message=tr('Password strength: Weak'), msg_level=MsgLevelType.MsgError)
case PasswordStrength.MODERATE:
return InputInfo(message=tr('Password strength: Moderate'), msg_level=MsgLevelType.MsgWarning)
case PasswordStrength.STRONG:
return InputInfo(message=tr('Password strength: Strong'), msg_level=MsgLevelType.MsgInfo)
while True:
result = await Input(