Removed legacy usage of Union[]
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from pathlib import Path
|
||||
from typing import Any, Union, Dict
|
||||
from typing import Any, Dict
|
||||
|
||||
from ..json import json_read, json_write
|
||||
from ..misc import nested_delete, nested_set
|
||||
@@ -14,14 +14,14 @@ DEFAULT_CONFIG_LOCATION: str = "config.json"
|
||||
|
||||
|
||||
@asyncable
|
||||
def config_get(key: str, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION) -> Any:
|
||||
def config_get(key: str, *path: str, config_file: str | Path = DEFAULT_CONFIG_LOCATION) -> Any:
|
||||
"""Get a value of the config key by its path provided
|
||||
For example, `foo.bar.key` has a path of `"foo", "bar"` and the key `"key"`
|
||||
|
||||
### Args:
|
||||
* key (`str`): Key that contains the value
|
||||
* *path (`str`): Path to the key that contains the value
|
||||
* config_file (`Union[str, Path]`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
|
||||
### Returns:
|
||||
* `Any`: Key's value
|
||||
@@ -53,14 +53,14 @@ def config_get(key: str, *path: str, config_file: Union[str, Path] = DEFAULT_CON
|
||||
|
||||
|
||||
@config_get.asynchronous
|
||||
async def config_get(key: str, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION) -> Any:
|
||||
async def config_get(key: str, *path: str, config_file: str | Path = DEFAULT_CONFIG_LOCATION) -> Any:
|
||||
"""Get a value of the config key by its path provided
|
||||
For example, `foo.bar.key` has a path of `"foo", "bar"` and the key `"key"`
|
||||
|
||||
### Args:
|
||||
* key (`str`): Key that contains the value
|
||||
* *path (`str`): Path to the key that contains the value
|
||||
* config_file (`Union[str, Path]`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
|
||||
### Returns:
|
||||
* `Any`: Key's value
|
||||
@@ -92,16 +92,14 @@ async def config_get(key: str, *path: str, config_file: Union[str, Path] = DEFAU
|
||||
|
||||
|
||||
@asyncable
|
||||
def config_set(
|
||||
key: str, value: Any, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION
|
||||
) -> None:
|
||||
def config_set(key: str, value: Any, *path: str, config_file: str | Path = DEFAULT_CONFIG_LOCATION) -> None:
|
||||
"""Set config's key by its path to the value
|
||||
|
||||
### Args:
|
||||
* key (`str`): Key that leads to the value
|
||||
* value (`Any`): Any JSON serializable data
|
||||
* *path (`str`): Path to the key of the target
|
||||
* config_file (`Union[str, Path]`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
|
||||
### Raises:
|
||||
* `KeyError`: Key is not found under path provided
|
||||
@@ -111,7 +109,7 @@ def config_set(
|
||||
|
||||
@config_set.asynchronous
|
||||
async def config_set(
|
||||
key: str, value: Any, *path: str, config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION
|
||||
key: str, value: Any, *path: str, config_file: str | Path = DEFAULT_CONFIG_LOCATION
|
||||
) -> None:
|
||||
"""Set config's key by its path to the value
|
||||
|
||||
@@ -119,7 +117,7 @@ async def config_set(
|
||||
* key (`str`): Key that leads to the value
|
||||
* value (`Any`): Any JSON serializable data
|
||||
* *path (`str`): Path to the key of the target
|
||||
* config_file (`Union[str, Path]`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
|
||||
### Raises:
|
||||
* `KeyError`: Key is not found under path provided
|
||||
@@ -132,7 +130,7 @@ def config_delete(
|
||||
key: str,
|
||||
*path: str,
|
||||
missing_ok: bool = False,
|
||||
config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION,
|
||||
config_file: str | Path = DEFAULT_CONFIG_LOCATION,
|
||||
) -> None:
|
||||
"""Set config's key by its path
|
||||
|
||||
@@ -140,7 +138,7 @@ def config_delete(
|
||||
* key (`str`): Key to delete
|
||||
* *path (`str`): Path to the key of the target
|
||||
* missing_ok (`bool`): Do not raise an exception if the key is missing. Defaults to `False`
|
||||
* config_file (`Union[str, Path]`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
|
||||
### Raises:
|
||||
* `KeyError`: Key is not found under path provided and `missing_ok` is `False`
|
||||
@@ -161,7 +159,7 @@ async def config_delete(
|
||||
key: str,
|
||||
*path: str,
|
||||
missing_ok: bool = False,
|
||||
config_file: Union[str, Path] = DEFAULT_CONFIG_LOCATION,
|
||||
config_file: str | Path = DEFAULT_CONFIG_LOCATION,
|
||||
) -> None:
|
||||
"""Set config's key by its path
|
||||
|
||||
@@ -169,7 +167,7 @@ async def config_delete(
|
||||
* key (`str`): Key to delete
|
||||
* *path (`str`): Path to the key of the target
|
||||
* missing_ok (`bool`): Do not raise an exception if the key is missing. Defaults to `False`
|
||||
* config_file (`Union[str, Path]`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
* config_file (`str | Path`, *optional*): Path-like object or path as a string of a location of the config file. Defaults to `"config.json"`
|
||||
|
||||
### Raises:
|
||||
* `KeyError`: Key is not found under path provided and `missing_ok` is `False`
|
||||
|
Reference in New Issue
Block a user