Coverage for src/configuraptor/loaders/__init__.py: 100%
11 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-21 15:50 +0200
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-21 15:50 +0200
1"""
2Loads loaders based on Python version.
3"""
5import typing
7from ._types import T_config
9# tomli used for every Python version now.
10from .loaders_shared import json, toml, yaml
12__all__ = ["get", "toml", "json", "yaml"]
14T_loader = typing.Callable[[typing.BinaryIO], T_config]
16LOADERS: dict[str, T_loader] = {
17 "toml": toml,
18 "json": json,
19 "yml": yaml,
20 "yaml": yaml,
21}
24def get(extension: str) -> T_loader:
25 """
26 Get the right loader for a specific extension.
27 """
28 extension = extension.removeprefix(".")
29 if loader := LOADERS.get(extension):
30 return loader
31 else:
32 raise ValueError(f"Invalid extension {extension}")