aboutsummaryrefslogtreecommitdiffstats
path: root/config_file/config_file.py
diff options
context:
space:
mode:
Diffstat (limited to 'config_file/config_file.py')
-rw-r--r--config_file/config_file.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/config_file/config_file.py b/config_file/config_file.py
index b5083ff..eba2c11 100644
--- a/config_file/config_file.py
+++ b/config_file/config_file.py
@@ -1,6 +1,6 @@
from pathlib import Path
from shutil import copyfile
-from typing import Any, Union
+from typing import Any, Callable, Union
from config_file.config_file_path import ConfigFilePath
from config_file.parsers.parse_value import parse_value
@@ -9,13 +9,11 @@ from config_file.utils import Default
class ConfigFile:
def __init__(self, file_path: Union[str, Path]) -> None:
- """
- Stores the config file path and expands it if needed, reads in
- the file contents, and determines what parser should be used for
- the given file.
+ """Stores the config file path and reads the file contents.
Args:
- file_path: The path to your configuration file.
+ file_path: Path to the configuration file. Supports tilde
+ (~) expansion for home directory.
Raises:
ValueError: If the specified file path does not have an extension
@@ -56,7 +54,7 @@ class ConfigFile:
self,
key: str,
parse_types: bool = False,
- return_type: Any = None,
+ return_type: Union[Callable[[Any], Any], None] = None,
default: Any = Default(None),
) -> Any:
"""
@@ -66,13 +64,12 @@ class ConfigFile:
key: The key to retrieve.
parse_types: Automatically parse ints, floats, booleans, dicts, and
lists. This recursively parses all types in whatever you're
- retrieving, not just a single type.
-
- e.g. If you are retrieving a section, all values in that
- section will be parsed.
-
+ retrieving, not just a single type. For example, if you are
+ retrieving a section, all values in that section will be
+ parsed.
return_type: The type to coerce the return value to.
default: The default value to return if the value of the key is empty.
+ If not specified, a KeyError will be raised if the key does not exist.
Returns:
The value of the key.