From 4951743bbf654a74b93577ff2dfa0d8906b74278 Mon Sep 17 00:00:00 2001 From: loathingKernel <142770+loathingKernel@users.noreply.github.com> Date: Fri, 2 Sep 2022 17:53:56 +0300 Subject: [PATCH] ConfigHelper: Protect name space from globals --- rare/utils/config_helper.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/rare/utils/config_helper.py b/rare/utils/config_helper.py index 50a992e9..086e7f1f 100644 --- a/rare/utils/config_helper.py +++ b/rare/utils/config_helper.py @@ -1,38 +1,38 @@ -from typing import Callable +from typing import Callable, Optional from legendary.core import LegendaryCore from legendary.utils.config import LGDConf -config: LGDConf = None -save_config: Callable[[], None] = None +_config: Optional[LGDConf] = None +_save_config: Optional[Callable[[], None]] = None def init_config_handler(core: LegendaryCore): - global config, save_config - config = core.lgd.config - save_config = core.lgd.save_config + global _config, _save_config + _config = core.lgd.config + _save_config = core.lgd.save_config def add_option(app_name: str, option: str, value: str): value = value.replace("%%", "%").replace("%", "%%") - if not config.has_section(app_name): - config[app_name] = {} + if not _config.has_section(app_name): + _config[app_name] = {} - config.set(app_name, option, value) - save_config() + _config.set(app_name, option, value) + _save_config() def remove_option(app_name, option): - if config.has_option(app_name, option): - config.remove_option(app_name, option) + if _config.has_option(app_name, option): + _config.remove_option(app_name, option) - if config.has_section(app_name) and not config[app_name]: - config.remove_section(app_name) + if _config.has_section(app_name) and not _config[app_name]: + _config.remove_section(app_name) - save_config() + _save_config() def remove_section(app_name): - if config.has_section(app_name): - config.remove_section(app_name) - save_config() + if _config.has_section(app_name): + _config.remove_section(app_name) + _save_config()