summaryrefslogtreecommitdiff
path: root/poezio/config.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-03-25 21:51:11 +0100
committermathieui <mathieui@mathieui.net>2021-04-02 17:44:36 +0200
commit3391a44206cfd56b57b51d58295da408e00b3439 (patch)
tree7b6ab65a9f4725913474c6098140a511c1d9c15c /poezio/config.py
parent5a59eb1d4eadaa425acf0cb527d51fda4bfc2b61 (diff)
downloadpoezio-3391a44206cfd56b57b51d58295da408e00b3439.tar.gz
poezio-3391a44206cfd56b57b51d58295da408e00b3439.tar.bz2
poezio-3391a44206cfd56b57b51d58295da408e00b3439.tar.xz
poezio-3391a44206cfd56b57b51d58295da408e00b3439.zip
fix: config, give up on typing Config.get
It is not possible to have a dynamic return type based on what would come out of a dict AND an optional parameter.
Diffstat (limited to 'poezio/config.py')
-rw-r--r--poezio/config.py28
1 files changed, 12 insertions, 16 deletions
diff --git a/poezio/config.py b/poezio/config.py
index 54fab069..89923eb2 100644
--- a/poezio/config.py
+++ b/poezio/config.py
@@ -19,7 +19,7 @@ import pkg_resources
from configparser import RawConfigParser, NoOptionError, NoSectionError
from pathlib import Path
from shutil import copy2
-from typing import Callable, Dict, List, Optional, Union, Tuple, cast, TypeVar
+from typing import Callable, Dict, List, Optional, Union, Tuple, cast, Any
from poezio.args import parse_args
from poezio import xdg
@@ -158,8 +158,6 @@ DEFAULT_CONFIG: ConfigDict = {
'muc_colors': {}
}
-T = TypeVar('T', bool, int, float, str)
-
class PoezioConfigParser(RawConfigParser):
def optionxform(self, value) -> str:
@@ -196,8 +194,8 @@ class Config:
def get(self,
option: str,
- default: Optional[T] = None,
- section=DEFSECTION) -> Optional[T]:
+ default: Optional[ConfigValue] = None,
+ section: str = DEFSECTION) -> Any:
"""
get a value from the config but return
a default value if it is not found
@@ -205,20 +203,18 @@ class Config:
returned
"""
if default is None:
- section = self.default.get('section')
- if section is not None:
- option = section.get(option)
- if option is not None:
- default = cast(T, option)
+ section_val = self.default.get(section)
+ if section_val is not None:
+ default = section_val.get(option)
- res: T
+ res: Optional[ConfigValue]
try:
if isinstance(default, bool):
res = self.configparser.getboolean(section, option)
- elif isinstance(default, float):
- res = self.configparser.getfloat(section, option)
elif isinstance(default, int):
res = self.configparser.getint(section, option)
+ elif isinstance(default, float):
+ res = self.configparser.getfloat(section, option)
else:
res = self.configparser.get(section, option)
except (NoOptionError, NoSectionError, ValueError, AttributeError):
@@ -732,11 +728,11 @@ LOGGING_CONFIG = {
# some help in the info buffer
firstrun = False
-# Global config object. Is setup in poezio.py
-config = None # type: Config
+# Global config object. Is setup for real in poezio.py
+config = Config(Path('/dev/null'))
# The logger object for this module
-log = logging.getLogger(__name__) # type: logging.Logger
+log: logging.Logger = logging.getLogger(__name__)
# The command-line options
options = None