Skip to content
Snippets Groups Projects

Add and fix more type hints

1 file
+ 10
8
Compare changes
  • Side-by-side
  • Inline
+ 10
8
@@ -21,14 +21,14 @@
#
# ** end header
#
from __future__ import annotations
import os
import warnings
import yaml
try:
optional_jsonschema_validate = None
optional_jsonschema_validate: Optional[Callable] = None
from jsonschema import validate as optional_jsonschema_validate
except ImportError:
pass
@@ -37,13 +37,15 @@ from configparser import ConfigParser
from os import environ, getcwd
from os.path import expanduser, isfile, join
from typing import Dict, Union, Callable, Optional
def _reset_config():
global _pycaosdbconf
_pycaosdbconf = ConfigParser(allow_no_value=False)
def configure(inifile):
def configure(inifile: str) -> list[str]:
"""read config from file.
Return a list of files which have successfully been parsed.
@@ -61,15 +63,15 @@ def configure(inifile):
return read_config
def get_config():
def get_config() -> ConfigParser:
global _pycaosdbconf
if ("_pycaosdbconf" not in globals() or _pycaosdbconf is None):
_reset_config()
return _pycaosdbconf
def config_to_yaml(config):
valobj = {}
def config_to_yaml(config: ConfigParser) -> Dict[str, Dict[str, Union[int, str, bool]]]:
valobj: Dict[str, Dict[str, Union[int, str, bool]]] = {}
for s in config.sections():
valobj[s] = {}
for key, value in config[s].items():
@@ -84,7 +86,7 @@ def config_to_yaml(config):
return valobj
def validate_yaml_schema(valobj):
def validate_yaml_schema(valobj: Dict[str, Dict[str, Union[int, str, bool]]]):
if optional_jsonschema_validate:
with open(os.path.join(os.path.dirname(__file__), "schema-pycaosdb-ini.yml")) as f:
schema = yaml.load(f, Loader=yaml.SafeLoader)
@@ -95,7 +97,7 @@ def validate_yaml_schema(valobj):
""")
def _read_config_files():
def _read_config_files() -> list[str]:
"""Read config files from different paths.
Read the config from either ``$PYCAOSDBINI`` or home directory (``~/.pylinkahead.ini``), and
Loading