|
@@ -1,7 +1,7 @@
|
|
|
from __future__ import annotations
|
|
|
|
|
|
from dataclasses import dataclass, field
|
|
|
-from typing import Any, Awaitable, Callable, ClassVar, Dict, Generic, List, Optional, Tuple, TypeVar, Union, cast
|
|
|
+from typing import Any, Awaitable, Callable, ClassVar, Dict, Generic, List, Optional, Tuple, TypeVar, cast
|
|
|
|
|
|
from typing_extensions import Concatenate, ParamSpec, Self
|
|
|
|
|
@@ -28,7 +28,7 @@ class RefreshableTarget:
|
|
|
locals: List[Any] = field(default_factory=list)
|
|
|
next_index: int = 0
|
|
|
|
|
|
- def run(self, func: Callable[..., Union[_T, Awaitable[_T]]]) -> Union[_T, Awaitable[_T]]:
|
|
|
+ def run(self, func: Callable[..., _T]) -> _T:
|
|
|
"""Run the function and return the result."""
|
|
|
RefreshableTarget.current_target = self
|
|
|
self.next_index = 0
|
|
@@ -42,7 +42,7 @@ class RefreshableTarget:
|
|
|
result = func(self.instance, *self.args, **self.kwargs)
|
|
|
assert isinstance(result, Awaitable)
|
|
|
return await result
|
|
|
- return wait_for_result()
|
|
|
+ return wait_for_result() # type: ignore
|
|
|
else:
|
|
|
with self.container:
|
|
|
if self.instance is None:
|
|
@@ -57,7 +57,7 @@ class RefreshableContainer(Element, component='refreshable.js'):
|
|
|
|
|
|
class refreshable(Generic[_P, _T]):
|
|
|
|
|
|
- def __init__(self, func: Callable[_P, Union[_T, Awaitable[_T]]]) -> None:
|
|
|
+ def __init__(self, func: Callable[_P, _T]) -> None:
|
|
|
"""Refreshable UI functions
|
|
|
|
|
|
The ``@ui.refreshable`` decorator allows you to create functions that have a ``refresh`` method.
|
|
@@ -83,7 +83,7 @@ class refreshable(Generic[_P, _T]):
|
|
|
return refresh
|
|
|
return attribute
|
|
|
|
|
|
- def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> Union[_T, Awaitable[_T]]:
|
|
|
+ def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _T:
|
|
|
self.prune()
|
|
|
target = RefreshableTarget(container=RefreshableContainer(), refreshable=self, instance=self.instance,
|
|
|
args=args, kwargs=kwargs)
|
|
@@ -133,7 +133,7 @@ class refreshable(Generic[_P, _T]):
|
|
|
|
|
|
class refreshable_method(Generic[_S, _P, _T], refreshable[_P, _T]):
|
|
|
|
|
|
- def __init__(self, func: Callable[Concatenate[_S, _P], Union[_T, Awaitable[_T]]]) -> None:
|
|
|
+ def __init__(self, func: Callable[Concatenate[_S, _P], _T]) -> None:
|
|
|
"""Refreshable UI methods
|
|
|
|
|
|
The `@ui.refreshable_method` decorator allows you to create methods that have a `refresh` method.
|