Skip to content

Commit d176532

Browse files
authored
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.
1 parent 094798b commit d176532

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

archinstall/lib/models/users.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,67 +36,66 @@ def color(self) -> str:
3636
case PasswordStrength.STRONG:
3737
return 'green'
3838

39-
@classmethod
40-
def strength(cls, password: str) -> Self:
39+
@staticmethod
40+
def strength(password: str) -> PasswordStrength:
4141
digit = any(character.isdigit() for character in password)
4242
upper = any(character.isupper() for character in password)
4343
lower = any(character.islower() for character in password)
4444
symbol = any(not character.isalnum() for character in password)
45-
return cls._check_password_strength(digit, upper, lower, symbol, len(password))
45+
return PasswordStrength._check_password_strength(digit, upper, lower, symbol, len(password))
4646

47-
@classmethod
47+
@staticmethod
4848
def _check_password_strength(
49-
cls,
5049
digit: bool,
5150
upper: bool,
5251
lower: bool,
5352
symbol: bool,
5453
length: int,
55-
) -> Self:
54+
) -> PasswordStrength:
5655
# suggested evaluation
5756
# https://github.com/archlinux/archinstall/issues/1304#issuecomment-1146768163
5857
if digit and upper and lower and symbol:
5958
match length:
6059
case num if 13 <= num:
61-
return cls.STRONG
60+
return PasswordStrength.STRONG
6261
case num if 11 <= num <= 12:
63-
return cls.MODERATE
62+
return PasswordStrength.MODERATE
6463
case num if 7 <= num <= 10:
65-
return cls.WEAK
64+
return PasswordStrength.WEAK
6665
case num if num <= 6:
67-
return cls.VERY_WEAK
66+
return PasswordStrength.VERY_WEAK
6867
elif digit and upper and lower:
6968
match length:
7069
case num if 14 <= num:
71-
return cls.STRONG
70+
return PasswordStrength.STRONG
7271
case num if 11 <= num <= 13:
73-
return cls.MODERATE
72+
return PasswordStrength.MODERATE
7473
case num if 7 <= num <= 10:
75-
return cls.WEAK
74+
return PasswordStrength.WEAK
7675
case num if num <= 6:
77-
return cls.VERY_WEAK
76+
return PasswordStrength.VERY_WEAK
7877
elif upper and lower:
7978
match length:
8079
case num if 15 <= num:
81-
return cls.STRONG
80+
return PasswordStrength.STRONG
8281
case num if 12 <= num <= 14:
83-
return cls.MODERATE
82+
return PasswordStrength.MODERATE
8483
case num if 7 <= num <= 11:
85-
return cls.WEAK
84+
return PasswordStrength.WEAK
8685
case num if num <= 6:
87-
return cls.VERY_WEAK
86+
return PasswordStrength.VERY_WEAK
8887
elif lower or upper:
8988
match length:
9089
case num if 18 <= num:
91-
return cls.STRONG
90+
return PasswordStrength.STRONG
9291
case num if 14 <= num <= 17:
93-
return cls.MODERATE
92+
return PasswordStrength.MODERATE
9493
case num if 9 <= num <= 13:
95-
return cls.WEAK
94+
return PasswordStrength.WEAK
9695
case num if num <= 8:
97-
return cls.VERY_WEAK
96+
return PasswordStrength.VERY_WEAK
9897

99-
return cls.VERY_WEAK
98+
return PasswordStrength.VERY_WEAK
10099

101100

102101
UserSerialization = TypedDict(

0 commit comments

Comments
 (0)