Replace an Any instance with TypedDict (#3261)
This commit is contained in:
parent
ae19299e5f
commit
aa444748b9
|
|
@ -1,6 +1,6 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import TYPE_CHECKING, Any, override
|
from typing import TYPE_CHECKING, TypedDict, override
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
|
|
@ -103,6 +103,9 @@ class PasswordStrength(Enum):
|
||||||
return PasswordStrength.VERY_WEAK
|
return PasswordStrength.VERY_WEAK
|
||||||
|
|
||||||
|
|
||||||
|
_UserSerialization = TypedDict('_UserSerialization', {'username': str, '!password': str, 'sudo': bool})
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class User:
|
class User:
|
||||||
username: str
|
username: str
|
||||||
|
|
@ -115,7 +118,7 @@ class User:
|
||||||
# if it's every going to be used
|
# if it's every going to be used
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def json(self) -> dict[str, str | bool]:
|
def json(self) -> _UserSerialization:
|
||||||
return {
|
return {
|
||||||
'username': self.username,
|
'username': self.username,
|
||||||
'!password': self.password,
|
'!password': self.password,
|
||||||
|
|
@ -123,7 +126,7 @@ class User:
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse(cls, config_users: list[dict[str, Any]]) -> list['User']:
|
def _parse(cls, config_users: list[_UserSerialization]) -> list['User']:
|
||||||
users = []
|
users = []
|
||||||
|
|
||||||
for entry in config_users:
|
for entry in config_users:
|
||||||
|
|
@ -153,8 +156,8 @@ class User:
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_arguments(
|
def parse_arguments(
|
||||||
cls,
|
cls,
|
||||||
config_users: list[dict[str, str]] | dict[str, dict[str, str]],
|
config_users: list[_UserSerialization] | dict[str, dict[str, str]],
|
||||||
config_superusers: list[dict[str, str]] | dict[str, dict[str, str]]
|
config_superusers: dict[str, dict[str, str]] | None
|
||||||
) -> list['User']:
|
) -> list['User']:
|
||||||
users = []
|
users = []
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue