-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
Description
WorkType in textual/worker.py is defined as:
WorkType: TypeAlias = Union[
Callable[[], Coroutine[None, None, ResultType]],
Callable[[], ResultType],
Awaitable[ResultType],
]Python's async def always produces Coroutine[Any, Any, ReturnType], not Coroutine[None, None, ReturnType]. This means every async def method passed to run_worker fails mypy strict checking:
error: Argument 1 to "run_worker" of "DOMNode" has incompatible type
"Callable[[], Coroutine[Any, Any, None]]";
expected "Callable[[], Coroutine[None, None, Never]] | Callable[[], Never] | Awaitable[Never]"
Reproduction
from textual.app import App, ComposeResult
from textual.widgets import Static
class MyApp(App):
def compose(self) -> ComposeResult:
yield Static("hello")
def on_mount(self) -> None:
self.run_worker(self._do_work) # mypy error here
async def _do_work(self) -> None:
passRun mypy with strict mode and this fails.
Suggested fix
WorkType: TypeAlias = Union[
Callable[[], Coroutine[Any, Any, ResultType]],
Callable[[], ResultType],
Awaitable[ResultType],
]Environment
- Textual 8.0.0
- Python 3.12
- mypy 1.15.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels