Use staticmethod for PasswordStrength methods (#4461)
The methods don't need access to the class, so they don't need to be classmethods. This change reduces the number of 'bad return' warnings seen when running Pyright, Pyrefly, and ty.
This commit is contained in:
parent
094798b496
commit
d1765323d8
|
|
@ -36,67 +36,66 @@ class PasswordStrength(Enum):
|
||||||
case PasswordStrength.STRONG:
|
case PasswordStrength.STRONG:
|
||||||
return 'green'
|
return 'green'
|
||||||
|
|
||||||
@classmethod
|
@staticmethod
|
||||||
def strength(cls, password: str) -> Self:
|
def strength(password: str) -> PasswordStrength:
|
||||||
digit = any(character.isdigit() for character in password)
|
digit = any(character.isdigit() for character in password)
|
||||||
upper = any(character.isupper() for character in password)
|
upper = any(character.isupper() for character in password)
|
||||||
lower = any(character.islower() for character in password)
|
lower = any(character.islower() for character in password)
|
||||||
symbol = any(not character.isalnum() for character in password)
|
symbol = any(not character.isalnum() for character in password)
|
||||||
return cls._check_password_strength(digit, upper, lower, symbol, len(password))
|
return PasswordStrength._check_password_strength(digit, upper, lower, symbol, len(password))
|
||||||
|
|
||||||
@classmethod
|
@staticmethod
|
||||||
def _check_password_strength(
|
def _check_password_strength(
|
||||||
cls,
|
|
||||||
digit: bool,
|
digit: bool,
|
||||||
upper: bool,
|
upper: bool,
|
||||||
lower: bool,
|
lower: bool,
|
||||||
symbol: bool,
|
symbol: bool,
|
||||||
length: int,
|
length: int,
|
||||||
) -> Self:
|
) -> PasswordStrength:
|
||||||
# suggested evaluation
|
# suggested evaluation
|
||||||
# https://github.com/archlinux/archinstall/issues/1304#issuecomment-1146768163
|
# https://github.com/archlinux/archinstall/issues/1304#issuecomment-1146768163
|
||||||
if digit and upper and lower and symbol:
|
if digit and upper and lower and symbol:
|
||||||
match length:
|
match length:
|
||||||
case num if 13 <= num:
|
case num if 13 <= num:
|
||||||
return cls.STRONG
|
return PasswordStrength.STRONG
|
||||||
case num if 11 <= num <= 12:
|
case num if 11 <= num <= 12:
|
||||||
return cls.MODERATE
|
return PasswordStrength.MODERATE
|
||||||
case num if 7 <= num <= 10:
|
case num if 7 <= num <= 10:
|
||||||
return cls.WEAK
|
return PasswordStrength.WEAK
|
||||||
case num if num <= 6:
|
case num if num <= 6:
|
||||||
return cls.VERY_WEAK
|
return PasswordStrength.VERY_WEAK
|
||||||
elif digit and upper and lower:
|
elif digit and upper and lower:
|
||||||
match length:
|
match length:
|
||||||
case num if 14 <= num:
|
case num if 14 <= num:
|
||||||
return cls.STRONG
|
return PasswordStrength.STRONG
|
||||||
case num if 11 <= num <= 13:
|
case num if 11 <= num <= 13:
|
||||||
return cls.MODERATE
|
return PasswordStrength.MODERATE
|
||||||
case num if 7 <= num <= 10:
|
case num if 7 <= num <= 10:
|
||||||
return cls.WEAK
|
return PasswordStrength.WEAK
|
||||||
case num if num <= 6:
|
case num if num <= 6:
|
||||||
return cls.VERY_WEAK
|
return PasswordStrength.VERY_WEAK
|
||||||
elif upper and lower:
|
elif upper and lower:
|
||||||
match length:
|
match length:
|
||||||
case num if 15 <= num:
|
case num if 15 <= num:
|
||||||
return cls.STRONG
|
return PasswordStrength.STRONG
|
||||||
case num if 12 <= num <= 14:
|
case num if 12 <= num <= 14:
|
||||||
return cls.MODERATE
|
return PasswordStrength.MODERATE
|
||||||
case num if 7 <= num <= 11:
|
case num if 7 <= num <= 11:
|
||||||
return cls.WEAK
|
return PasswordStrength.WEAK
|
||||||
case num if num <= 6:
|
case num if num <= 6:
|
||||||
return cls.VERY_WEAK
|
return PasswordStrength.VERY_WEAK
|
||||||
elif lower or upper:
|
elif lower or upper:
|
||||||
match length:
|
match length:
|
||||||
case num if 18 <= num:
|
case num if 18 <= num:
|
||||||
return cls.STRONG
|
return PasswordStrength.STRONG
|
||||||
case num if 14 <= num <= 17:
|
case num if 14 <= num <= 17:
|
||||||
return cls.MODERATE
|
return PasswordStrength.MODERATE
|
||||||
case num if 9 <= num <= 13:
|
case num if 9 <= num <= 13:
|
||||||
return cls.WEAK
|
return PasswordStrength.WEAK
|
||||||
case num if num <= 8:
|
case num if num <= 8:
|
||||||
return cls.VERY_WEAK
|
return PasswordStrength.VERY_WEAK
|
||||||
|
|
||||||
return cls.VERY_WEAK
|
return PasswordStrength.VERY_WEAK
|
||||||
|
|
||||||
|
|
||||||
UserSerialization = TypedDict(
|
UserSerialization = TypedDict(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue