Mod: make mypy happy

Moved the enabled setter next to the property, and made type hints
more accurate
This commit is contained in:
Toast 2025-05-14 17:37:13 +02:00
parent 3a8406cb19
commit ef25e8a026

View file

@ -11,25 +11,35 @@ class Mod:
def name(self) -> str | None:
if "name" not in self.__config:
return None
return self.__config["name"]
return self.__config["name"].as_string()
@property
def description(self) -> str | None:
if "description" not in self.__config.keys():
return None
else:
return self.__config["description"]
return self.__config["description"].as_string()
@property
def author(self) -> str | None:
if "author" not in self.__config:
return None
return self.__config["author"]
return self.__config["author"].as_string()
@property
def enabled(self) -> bool:
return True if self.__enabled == "true" else False
@enabled.setter
def enabled(self, value: bool) -> None:
if value == self.__enabled:
# Nothing to do
return
with open(self.__path + "config.toml", "w") as config_file:
self.__config["enabled"] = value
tomlkit.dump(self.__config, config_file)
def __init__(self, path: str) -> None:
self.__path = path
@ -41,16 +51,6 @@ class Mod:
else:
self.__enabled = self.__config["enabled"]
@enabled.setter
def enabled(self, value: bool) -> None:
if value == self.__enabled:
# Nothing to do
return
with open(self.__path + "config.toml", "w") as config_file:
self.__config["enabled"] = value
tomlkit.dump(self.__config, config_file)
def __str__(self) -> str:
return f"Mod({self.__path})"