Skip to content

Commit fbc6b3f

Browse files
committed
Fix typing
1 parent 2f433bd commit fbc6b3f

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

src/daq_config_server/client.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import operator
22
from logging import Logger, getLogger
33
from pathlib import Path
4-
from typing import Any, TypeVar, get_origin
4+
from typing import Any, TypeVar, get_origin, overload
55

66
import requests
77
from cachetools import TTLCache, cachedmethod
@@ -13,13 +13,18 @@
1313

1414
from .constants import ENDPOINTS
1515

16-
T = TypeVar("T", str, bytes, dict[Any, Any], BaseModel)
16+
T = TypeVar("T", bound=BaseModel)
1717

1818

1919
class TypeConversionException(Exception): ...
2020

2121

22-
def _get_mime_type(requested_return_type: type[T]) -> ValidAcceptHeaders:
22+
def _get_mime_type(
23+
requested_return_type: type[str]
24+
| type[bytes]
25+
| type[dict[str, Any]]
26+
| type[BaseModel],
27+
) -> ValidAcceptHeaders:
2328
# Get correct mapping for typed dict or plain dict
2429
if (
2530
get_origin(requested_return_type) is dict
@@ -135,12 +140,44 @@ def _get(
135140

136141
return content
137142

143+
@overload
138144
def get_file_contents(
139145
self,
140-
file_path: Path | str,
141-
desired_return_type: type[T] = str,
146+
file_path: str | Path,
147+
desired_return_type: type[str] = str,
142148
reset_cached_result: bool = False,
143-
) -> T:
149+
) -> str: ...
150+
151+
@overload
152+
def get_file_contents(
153+
self,
154+
file_path: str | Path,
155+
desired_return_type: type[bytes],
156+
reset_cached_result: bool = False,
157+
) -> bytes: ...
158+
159+
@overload
160+
def get_file_contents(
161+
self,
162+
file_path: str | Path,
163+
desired_return_type: type[dict[str, Any]],
164+
reset_cached_result: bool = False,
165+
) -> dict[str, Any]: ...
166+
167+
@overload
168+
def get_file_contents(
169+
self,
170+
file_path: str | Path,
171+
desired_return_type: type[T],
172+
reset_cached_result: bool = False,
173+
) -> T: ...
174+
175+
def get_file_contents(
176+
self,
177+
file_path: str | Path,
178+
desired_return_type: type[Any] = str,
179+
reset_cached_result: bool = False,
180+
) -> Any:
144181
"""
145182
Get contents of a file from the config server in the format specified.
146183
Optionally look for cached result before making request.

0 commit comments

Comments
 (0)