Removed legacy usage of Union[]

This commit is contained in:
2024-12-26 18:36:57 +01:00
parent 95d04308bd
commit aa2c778a6a
13 changed files with 128 additions and 149 deletions

View File

@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Any, Union
from typing import Any
import aiofiles
@@ -13,11 +13,11 @@ except ImportError:
@asyncable
def json_read(path: Union[str, Path]) -> Any:
def json_read(path: str | Path) -> Any:
"""Read contents of a JSON file
### Args:
* path (`Union[str, Path]`): Path-like object or path as a string
* path (`str | Path`): Path-like object or path as a string
### Returns:
* `Any`: File contents
@@ -29,11 +29,11 @@ def json_read(path: Union[str, Path]) -> Any:
@json_read.asynchronous
async def json_read(path: Union[str, Path]) -> Any:
async def json_read(path: str | Path) -> Any:
"""Read contents of a JSON file
### Args:
* path (`Union[str, Path]`): Path-like object or path as a string
* path (`str | Path`): Path-like object or path as a string
### Returns:
* `Any`: File contents
@@ -45,12 +45,12 @@ async def json_read(path: Union[str, Path]) -> Any:
@asyncable
def json_write(data: Any, path: Union[str, Path]) -> None:
def json_write(data: Any, path: str | Path) -> None:
"""Write contents to a JSON file
### Args:
* data (`Any`): Contents to write. Must be a JSON serializable
* path (`Union[str, Path]`): Path-like object or path as a string of a destination
* path (`str | Path`): Path-like object or path as a string of a destination
"""
with open(str(path), mode="w", encoding="utf-8") as f:
f.write(
@@ -61,12 +61,12 @@ def json_write(data: Any, path: Union[str, Path]) -> None:
@json_write.asynchronous
async def json_write(data: Any, path: Union[str, Path]) -> None:
async def json_write(data: Any, path: str | Path) -> None:
"""Write contents to a JSON file
### Args:
* data (`Any`): Contents to write. Must be a JSON serializable
* path (`Union[str, Path]`): Path-like object or path as a string of a destination
* path (`str | Path`): Path-like object or path as a string of a destination
"""
async with aiofiles.open(str(path), mode="w", encoding="utf-8") as f:
await f.write(