From 0f70ab76795eab4efad393664ce7d01173e4f6c4 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Tue, 5 Mar 2024 16:22:49 +0000 Subject: [PATCH] config: Use logic from zulip_tools, to support bools. --- scripts/lib/zulip_tools.py | 2 +- zproject/config.py | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index 8a42746eb1..1287fa354b 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -588,7 +588,7 @@ def get_config( config_file: configparser.RawConfigParser, section: str, key: str, - default_value: None, + default_value: None = None, ) -> Optional[str]: ... @overload def get_config( diff --git a/zproject/config.py b/zproject/config.py index dbcac359a9..c4fdd35f8f 100644 --- a/zproject/config.py +++ b/zproject/config.py @@ -1,6 +1,8 @@ import configparser import os -from typing import Optional, overload +from typing import Optional, Union, overload + +from scripts.lib.zulip_tools import get_config as get_config_from_file class ZulipSettingsError(Exception): @@ -22,12 +24,12 @@ else: secrets_file.read(os.path.join(DEPLOY_ROOT, "zproject/dev-secrets.conf")) -@overload -def get_secret(key: str, default_value: str, development_only: bool = False) -> str: ... @overload def get_secret( - key: str, default_value: Optional[str] = None, development_only: bool = False + key: str, default_value: None = None, development_only: bool = False ) -> Optional[str]: ... +@overload +def get_secret(key: str, default_value: str, development_only: bool = False) -> str: ... def get_secret( key: str, default_value: Optional[str] = None, development_only: bool = False ) -> Optional[str]: @@ -45,12 +47,16 @@ def get_mandatory_secret(key: str) -> str: return secret +@overload +def get_config(section: str, key: str, default_value: None = None) -> Optional[str]: ... @overload def get_config(section: str, key: str, default_value: str) -> str: ... @overload -def get_config(section: str, key: str, default_value: Optional[str] = None) -> Optional[str]: ... -def get_config(section: str, key: str, default_value: Optional[str] = None) -> Optional[str]: - return config_file.get(section, key, fallback=default_value) +def get_config(section: str, key: str, default_value: bool) -> bool: ... +def get_config( + section: str, key: str, default_value: Union[str, bool, None] = None +) -> Union[str, bool, None]: + return get_config_from_file(config_file, section, key, default_value) def get_from_file_if_exists(path: str) -> str: