Skip to content

Commit 438f952

Browse files
committed
Try to do type check in the config
1 parent e35445b commit 438f952

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

nameless/config.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1+
from datetime import datetime
12
from pathlib import Path
23
from tomllib import loads
4+
from typing import TypedDict
35

46
__all__ = ["nameless_config"]
57

8+
9+
class NamelessMetadata(TypedDict):
10+
version: str
11+
description: str
12+
support_server: str
13+
start_time: datetime
14+
is_shutting_down: bool
15+
16+
17+
class NamelessCommands(TypedDict):
18+
prefixes: list[str]
19+
20+
21+
class NamelessBlacklist(TypedDict):
22+
users: list[int]
23+
guilds: list[int]
24+
25+
26+
class NamelessConfig(TypedDict):
27+
nameless: NamelessMetadata
28+
command: NamelessCommands
29+
blacklist: NamelessBlacklist
30+
31+
632
_cfg_path: Path = Path(__file__).parent.parent.absolute() / "nameless.toml"
733

834
with open(_cfg_path, encoding="utf-8") as f:
935
_content: str = f.read()
1036

11-
nameless_config = loads(_content)
37+
# Maybe add a type checker here, using the annotation from the TypedDict
38+
raw_config = loads(_content)
39+
nameless_config: NamelessConfig = NamelessConfig(**raw_config) # pyright: ignore[reportAny]

0 commit comments

Comments
 (0)