|
1 | 1 | import abc |
2 | 2 | import asyncio |
3 | 3 | from functools import wraps |
4 | | -from typing import Callable, Awaitable, Dict, Any, AsyncIterator |
| 4 | +from typing import Callable, Awaitable, Dict, Any, AsyncIterator, TypeVar, cast |
5 | 5 |
|
6 | 6 | from anyio import create_task_group, TaskGroup # type: ignore |
7 | 7 | from jsonpatch import make_patch, apply_patch |
@@ -106,7 +106,7 @@ class SharedStateRenderer(SingleStateRenderer): |
106 | 106 |
|
107 | 107 | def __init__(self, layout: Layout) -> None: |
108 | 108 | super().__init__(layout) |
109 | | - self._model_state = {} |
| 109 | + self._model_state: Any = {} |
110 | 110 | self._update_queues: Dict[str, asyncio.Queue[LayoutUpdate]] = {} |
111 | 111 |
|
112 | 112 | @async_resource |
@@ -147,21 +147,24 @@ async def _join_event(self) -> AsyncIterator[asyncio.Event]: |
147 | 147 | event.set() |
148 | 148 |
|
149 | 149 |
|
150 | | -def _apply_layout_update(doc: Dict[str, Any], update: LayoutUpdate) -> Dict[str, Any]: |
| 150 | +def _apply_layout_update(doc: Dict[str, Any], update: LayoutUpdate) -> Any: |
151 | 151 | return apply_patch( |
152 | 152 | doc, [{**c, "path": update.path + c["path"]} for c in update.changes] |
153 | 153 | ) |
154 | 154 |
|
155 | 155 |
|
156 | | -def _async_log_exceptions(function): |
| 156 | +_F = TypeVar("_F", bound=Callable[..., Any]) |
| 157 | + |
| 158 | + |
| 159 | +def _async_log_exceptions(function: _F) -> _F: |
157 | 160 | # BUG: https://github.com/agronholm/anyio/issues/155 |
158 | 161 |
|
159 | 162 | @wraps(function) |
160 | | - async def wrapper(*args, **kwargs): |
| 163 | + async def wrapper(*args: Any, **kwargs: Any) -> Any: |
161 | 164 | try: |
162 | 165 | return await function(*args, **kwargs) |
163 | 166 | except Exception: |
164 | 167 | logger.exception(f"Failure in {function}") |
165 | 168 | raise |
166 | 169 |
|
167 | | - return wrapper |
| 170 | + return cast(_F, wrapper) |
0 commit comments