diff --git a/src/antsibull_core/test.yml b/src/antsibull_core/test.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/antsibull_core/utils/io.py b/src/antsibull_core/utils/io.py index 8ec2aa6..6a0d864 100644 --- a/src/antsibull_core/utils/io.py +++ b/src/antsibull_core/utils/io.py @@ -7,6 +7,7 @@ import os import os.path +import typing as t import aiofiles @@ -14,10 +15,15 @@ from ..logging import log +if t.TYPE_CHECKING: + # TODO PY3.8: Use __future__.annotations instead of quoting annotations + # pylint:disable=unused-import + from _typeshed import StrOrBytesPath + mlog = log.fields(mod=__name__) -async def copy_file(source_path: str, dest_path: str) -> None: +async def copy_file(source_path: "StrOrBytesPath", dest_path: "StrOrBytesPath") -> None: """ Copy content from one file to another. @@ -64,7 +70,7 @@ async def copy_file(source_path: str, dest_path: str) -> None: flog.debug('Leave') -async def write_file(filename: str, content: str) -> None: +async def write_file(filename: "StrOrBytesPath", content: str) -> None: flog = mlog.fields(func='write_file') flog.debug('Enter') @@ -93,7 +99,7 @@ async def write_file(filename: str, content: str) -> None: flog.debug('Leave') -async def read_file(filename: str, encoding: str = 'utf-8') -> str: +async def read_file(filename: "StrOrBytesPath", encoding: str = 'utf-8') -> str: flog = mlog.fields(func='read_file') flog.debug('Enter') diff --git a/src/antsibull_core/yaml.py b/src/antsibull_core/yaml.py index 35099f3..ad22da5 100644 --- a/src/antsibull_core/yaml.py +++ b/src/antsibull_core/yaml.py @@ -22,6 +22,11 @@ from yaml import SafeLoader as _SafeLoader from yaml import SafeDumper as _SafeDumper +if t.TYPE_CHECKING: + # TODO PY3.8: Use __future__.annotations instead of quoting annotations + # pylint:disable=unused-import + from _typeshed import StrOrBytesPath + def load_yaml_bytes(data: bytes) -> t.Any: """ @@ -30,7 +35,7 @@ def load_yaml_bytes(data: bytes) -> t.Any: return yaml.load(data, Loader=_SafeLoader) -def load_yaml_file(path: str) -> t.Any: +def load_yaml_file(path: "StrOrBytesPath") -> t.Any: """ Load and parse YAML file ``path``. """ @@ -38,7 +43,7 @@ def load_yaml_file(path: str) -> t.Any: return yaml.load(stream, Loader=_SafeLoader) -def store_yaml_file(path: str, content: t.Any) -> None: +def store_yaml_file(path: "StrOrBytesPath", content: t.Any) -> None: """ Store ``content`` as YAML file under ``path``. """