diff --git a/src/textual/_work_decorator.py b/src/textual/_work_decorator.py index 71bd67ac1e..e38a286571 100644 --- a/src/textual/_work_decorator.py +++ b/src/textual/_work_decorator.py @@ -6,7 +6,16 @@ from functools import partial, wraps from inspect import iscoroutinefunction -from typing import TYPE_CHECKING, Callable, Coroutine, TypeVar, Union, cast, overload +from typing import ( + TYPE_CHECKING, + Any, + Callable, + Coroutine, + TypeVar, + Union, + cast, + overload, +) from typing_extensions import ParamSpec, TypeAlias @@ -14,7 +23,6 @@ from .worker import Worker -FactoryParamSpec = ParamSpec("FactoryParamSpec") DecoratorParamSpec = ParamSpec("DecoratorParamSpec") ReturnType = TypeVar("ReturnType") @@ -22,7 +30,7 @@ [ Union[ Callable[DecoratorParamSpec, ReturnType], - Callable[DecoratorParamSpec, Coroutine[None, None, ReturnType]], + Callable[DecoratorParamSpec, Coroutine[Any, Any, ReturnType]], ] ], Callable[DecoratorParamSpec, "Worker[ReturnType]"], @@ -35,7 +43,7 @@ class WorkerDeclarationError(Exception): @overload def work( - method: Callable[FactoryParamSpec, Coroutine[None, None, ReturnType]], + method: Callable[DecoratorParamSpec, Coroutine[Any, Any, ReturnType]], *, name: str = "", group: str = "default", @@ -48,7 +56,7 @@ def work( @overload def work( - method: Callable[FactoryParamSpec, ReturnType], + method: Callable[DecoratorParamSpec, ReturnType], *, name: str = "", group: str = "default", @@ -68,13 +76,13 @@ def work( exclusive: bool = False, description: str | None = None, thread: bool = False, -) -> Decorator[..., ReturnType]: ... +) -> Decorator[DecoratorParamSpec, ReturnType]: ... def work( method: ( - Callable[FactoryParamSpec, ReturnType] - | Callable[FactoryParamSpec, Coroutine[None, None, ReturnType]] + Callable[DecoratorParamSpec, ReturnType] + | Callable[DecoratorParamSpec, Coroutine[Any, Any, ReturnType]] | None ) = None, *, @@ -84,7 +92,10 @@ def work( exclusive: bool = False, description: str | None = None, thread: bool = False, -) -> Callable[FactoryParamSpec, Worker[ReturnType]] | Decorator: +) -> ( + Callable[DecoratorParamSpec, Worker[ReturnType]] + | Decorator[DecoratorParamSpec, ReturnType] +): """A decorator used to create [workers](/guide/workers). Args: @@ -102,7 +113,7 @@ def work( def decorator( method: ( Callable[DecoratorParamSpec, ReturnType] - | Callable[DecoratorParamSpec, Coroutine[None, None, ReturnType]] + | Callable[DecoratorParamSpec, Coroutine[Any, Any, ReturnType]] ) ) -> Callable[DecoratorParamSpec, Worker[ReturnType]]: """The decorator."""