Skip to content

Commit b0571fe

Browse files
committed
Add comprehensive celery-stubs type annotations
Significantly expanded type stubs for the celery package: - Added many new modules: app/annotations, app/autoretry, app/backends, app/builtins, app/defaults, app/trace, apps/beat, apps/multi - Added backend stubs: arangodb, asynchronous, azureblockblob, cache, cassandra, consul, cosmosdbsql, couchbase, couchdb, dynamodb, elasticsearch, filesystem, gcs, mongodb, redis, rpc, s3 - Added bin stubs: amqp, base, beat, call, celery, control, events, graph, list, logtool, migrate, multi, purge, result, shell, upgrade, worker - Added concurrency stubs: asynpool, base, eventlet, gevent, prefork, solo, thread - Added worker stubs: components, consumer/*, control, heartbeat, loops, pidbox, request, state, strategy, worker - Added utils stubs: collections, debug, dispatch, functional, graph, imports, iso8601, log, nodenames, objects, serialization, term, text, threads, time, timer2 - Enhanced existing module type annotations with more complete signatures - Added @OverRide decorators for proper method override annotations
1 parent f9abac4 commit b0571fe

File tree

149 files changed

+5298
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+5298
-238
lines changed

celery-stubs/__init__.pyi

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
from celery import local
2-
from celery._state import current_app, current_task
1+
from types import ModuleType
2+
from typing import Any, NamedTuple
3+
4+
from celery import execute as execute
5+
from celery import local as local
6+
from celery import messaging as messaging
7+
from celery._state import current_app as current_app
8+
from celery._state import current_task as current_task
9+
from celery.app import bugreport as bugreport
310
from celery.app import shared_task
411
from celery.app.base import Celery
512
from celery.app.task import Task
@@ -13,22 +20,77 @@ from celery.canvas import (
1320
xmap,
1421
xstarmap,
1522
)
23+
from celery.canvas import maybe_signature as maybe_signature
24+
from celery.canvas import signature as subtask
1625
from celery.utils import uuid
1726

27+
# These are lazy module proxies at runtime
28+
log: ModuleType
29+
registry: ModuleType
30+
31+
class version_info_t(NamedTuple):
32+
major: int
33+
minor: int
34+
micro: int
35+
releaselevel: str
36+
serial: str
37+
38+
VERSION: version_info_t
39+
version_info: version_info_t
40+
VERSION_BANNER: str
41+
SERIES: str
42+
__version__: str
43+
__author__: str
44+
__contact__: str
45+
__homepage__: str
46+
__docformat__: str
47+
48+
def _find_option_with_arg(
49+
argv: list[str], short_opts: str | None = ..., long_opts: list[str] | None = ...
50+
) -> str | None: ...
51+
def maybe_patch_concurrency(
52+
argv: list[str] | None = ...,
53+
short_opts: str | None = ...,
54+
long_opts: list[str] | None = ...,
55+
patches: dict[str, Any] | None = ...,
56+
) -> None: ...
57+
58+
# Note: These are lazy module proxies at runtime
59+
# log, execute, registry, messaging are module-level lazy proxies
60+
1861
__all__ = (
62+
"SERIES",
63+
"VERSION",
64+
"VERSION_BANNER",
1965
"Celery",
2066
"Signature",
2167
"Task",
68+
"__author__",
69+
"__contact__",
70+
"__docformat__",
71+
"__homepage__",
72+
"__version__",
73+
"_find_option_with_arg",
74+
"bugreport",
2275
"chain",
2376
"chord",
2477
"chunks",
2578
"current_app",
2679
"current_task",
80+
"execute",
2781
"group",
2882
"local",
83+
"log",
84+
"maybe_patch_concurrency",
85+
"maybe_signature",
86+
"messaging",
87+
"registry",
2988
"shared_task",
3089
"signature",
90+
"subtask",
3191
"uuid",
92+
"version_info",
93+
"version_info_t",
3294
"xmap",
3395
"xstarmap",
3496
)

celery-stubs/__main__.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from typing import Any
2+
3+
__all__ = ("main",)
4+
5+
def main() -> Any: ...

celery-stubs/_state.pyi

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1+
from collections.abc import Callable
12
from typing import Any
23

34
from celery.app.base import Celery
45
from celery.app.task import Task
6+
from celery.local import Proxy
57

6-
current_app: Celery
7-
current_task: Task[Any, Any]
8+
__all__ = (
9+
"connect_on_app_finalize",
10+
"current_app",
11+
"current_task",
12+
"get_current_app",
13+
"get_current_task",
14+
"get_current_worker_task",
15+
"set_default_app",
16+
)
17+
18+
current_app: Proxy[Celery]
19+
current_task: Proxy[Task[Any, Any]]
820

921
def get_current_task() -> Task[Any, Any]: ...
22+
def get_current_app() -> Celery: ...
23+
def get_current_worker_task() -> Task[Any, Any] | None: ...
24+
def set_default_app(app: Celery) -> None: ...
25+
def connect_on_app_finalize(
26+
callback: Callable[[Celery], Any],
27+
) -> Callable[[Celery], Any]: ...

celery-stubs/app/__init__.pyi

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,56 @@ from typing import (
88
overload,
99
)
1010

11-
from celery.app import beat as beat
1211
from celery.app import control as control
1312
from celery.app import events as events
1413
from celery.app import task as task
14+
from celery.app.base import Celery
1515
from celery.app.task import Context, Task
16+
from celery.local import Proxy
1617
from celery.utils.threads import _LocalStack
1718
from typing_extensions import ParamSpec
1819

20+
__all__ = (
21+
"AppPickler",
22+
"Celery",
23+
"app_or_default",
24+
"bugreport",
25+
"default_app",
26+
"disable_trace",
27+
"enable_trace",
28+
"pop_current_task",
29+
"push_current_task",
30+
"shared_task",
31+
)
32+
33+
class AppPickler:
34+
def __call__(self, cls: type[Celery], *args: Any) -> Celery: ...
35+
def build_kwargs(self, *args: Any) -> dict[str, Any]: ...
36+
def build_standard_kwargs(
37+
self,
38+
main: str | None,
39+
changes: dict[str, Any] | None,
40+
loader: Any,
41+
backend: Any,
42+
amqp: Any,
43+
events: Any, # noqa: F811
44+
log: Any,
45+
control: Any, # noqa: F811
46+
accept_magic_kwargs: bool,
47+
config_source: Any | None = None,
48+
) -> dict[str, Any]: ...
49+
def construct(self, cls: type[Celery], **kwargs: Any) -> Celery: ...
50+
def prepare(self, app: Celery, **kwargs: Any) -> dict[str, Any]: ...
51+
52+
def app_or_default(app: Celery | None = ...) -> Celery: ...
53+
def bugreport(app: Celery | None = ...) -> str: ...
54+
def enable_trace() -> None: ...
55+
def disable_trace() -> None: ...
56+
def push_current_task(obj: Task[Any, Any]) -> None: ...
57+
def pop_current_task() -> Task[Any, Any] | None: ...
58+
59+
default_app: Proxy[Celery]
60+
1961
_T = TypeVar("_T", bound=Task[Any, Any])
2062
_P = ParamSpec("_P")
2163
_R = TypeVar("_R")

celery-stubs/app/amqp.pyi

Lines changed: 158 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,158 @@
1-
class AMQP: ...
1+
from datetime import datetime
2+
from typing import Any, NamedTuple, TypeAlias
3+
4+
import kombu
5+
import kombu.pools
6+
from celery.app.base import Celery
7+
from celery.app.routes import Router as RouterClass
8+
from kombu.transport.base import StdChannel
9+
10+
__all__ = ("AMQP", "Queues", "task_message")
11+
12+
class task_message(NamedTuple):
13+
headers: dict[str, Any]
14+
properties: dict[str, Any]
15+
body: tuple[Any, ...]
16+
sent_event: dict[str, Any] | None
17+
18+
class Queues(dict[str, kombu.Queue]):
19+
def __init__(
20+
self,
21+
queues: list[kombu.Queue] | dict[str, kombu.Queue] | None = None,
22+
default_exchange: kombu.Exchange | None = None,
23+
create_missing: bool = True,
24+
create_missing_queue_type: str | None = None,
25+
create_missing_queue_exchange_type: str | None = None,
26+
autoexchange: kombu.Exchange | None = None,
27+
max_priority: int | None = None,
28+
default_routing_key: str | None = None,
29+
) -> None: ...
30+
def __missing__(self, name: str) -> kombu.Queue: ...
31+
def add(self, queue: kombu.Queue, **kwargs: Any) -> None: ...
32+
def add_compat(self, name: str, **options: Any) -> kombu.Queue: ...
33+
@property
34+
def consume_from(self) -> dict[str, kombu.Queue]: ...
35+
def deselect(self, exclude: list[str]) -> None: ...
36+
def format(self, indent: int = 0, indent_first: bool = True) -> str: ...
37+
def new_missing(self, name: str) -> kombu.Queue: ...
38+
def select(self, include: list[str]) -> None: ...
39+
def select_add(self, queue: kombu.Queue, **kwargs: Any) -> None: ...
40+
41+
# Type alias to avoid conflict with AMQP.Queues method
42+
_Queues: TypeAlias = Queues
43+
44+
class AMQP:
45+
# Class attributes
46+
BrokerConnection: type[kombu.Connection]
47+
Connection: type[kombu.Connection]
48+
Consumer: type[kombu.Consumer]
49+
Producer: type[kombu.Producer]
50+
queues_cls: type[_Queues]
51+
argsrepr_maxsize: int
52+
kwargsrepr_maxsize: int
53+
autoexchange: kombu.Exchange | None
54+
55+
app: Celery
56+
57+
def __init__(self, app: Celery) -> None: ...
58+
def TaskConsumer(
59+
self,
60+
channel: StdChannel,
61+
queues: list[kombu.Queue] | None = None,
62+
accept: list[str] | None = None,
63+
**kw: Any,
64+
) -> kombu.Consumer: ...
65+
def Queues(
66+
self,
67+
queues: list[kombu.Queue] | dict[str, kombu.Queue],
68+
create_missing: bool | None = None,
69+
create_missing_queue_type: str | None = None,
70+
create_missing_queue_exchange_type: str | None = None,
71+
autoexchange: kombu.Exchange | None = None,
72+
max_priority: int | None = None,
73+
) -> _Queues: ...
74+
def Router(
75+
self,
76+
queues: _Queues | None = None,
77+
create_missing: bool | None = None,
78+
) -> RouterClass: ...
79+
def flush_routes(self) -> None: ...
80+
def as_task_v1(
81+
self,
82+
task_id: str,
83+
name: str,
84+
args: tuple[Any, ...] | None = None,
85+
kwargs: dict[str, Any] | None = None,
86+
countdown: float | None = None,
87+
eta: datetime | None = None,
88+
group_id: str | None = None,
89+
group_index: int | None = None,
90+
expires: float | datetime | None = None,
91+
retries: int = 0,
92+
chord: Any | None = None,
93+
callbacks: list[Any] | None = None,
94+
errbacks: list[Any] | None = None,
95+
reply_to: str | None = None,
96+
time_limit: int | None = None,
97+
soft_time_limit: int | None = None,
98+
create_sent_event: bool = False,
99+
root_id: str | None = None,
100+
parent_id: str | None = None,
101+
shadow: str | None = None,
102+
now: datetime | None = None,
103+
timezone: Any | None = None,
104+
**compat_kwargs: Any,
105+
) -> task_message: ...
106+
def as_task_v2(
107+
self,
108+
task_id: str,
109+
name: str,
110+
args: tuple[Any, ...] | None = None,
111+
kwargs: dict[str, Any] | None = None,
112+
countdown: float | None = None,
113+
eta: datetime | None = None,
114+
group_id: str | None = None,
115+
group_index: int | None = None,
116+
expires: float | datetime | None = None,
117+
retries: int = 0,
118+
chord: Any | None = None,
119+
callbacks: list[Any] | None = None,
120+
errbacks: list[Any] | None = None,
121+
reply_to: str | None = None,
122+
time_limit: int | None = None,
123+
soft_time_limit: int | None = None,
124+
create_sent_event: bool = False,
125+
root_id: str | None = None,
126+
parent_id: str | None = None,
127+
shadow: str | None = None,
128+
chain: Any | None = None,
129+
now: datetime | None = None,
130+
timezone: Any | None = None,
131+
origin: str | None = None,
132+
ignore_result: bool = False,
133+
argsrepr: str | None = None,
134+
kwargsrepr: str | None = None,
135+
stamped_headers: list[str] | None = None,
136+
replaced_task_nesting: int = 0,
137+
**options: Any,
138+
) -> task_message: ...
139+
@property
140+
def create_task_message(self) -> Any: ...
141+
@property
142+
def default_exchange(self) -> kombu.Exchange: ...
143+
@property
144+
def default_queue(self) -> kombu.Queue: ...
145+
@property
146+
def producer_pool(self) -> kombu.pools.ProducerPool: ...
147+
@property
148+
def publisher_pool(self) -> kombu.pools.ProducerPool: ...
149+
@property
150+
def queues(self) -> _Queues: ...
151+
@property
152+
def router(self) -> RouterClass: ...
153+
@property
154+
def routes(self) -> list[dict[str, Any]]: ...
155+
@property
156+
def send_task_message(self) -> Any: ...
157+
@property
158+
def utc(self) -> bool: ...

celery-stubs/app/annotations.pyi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import Any
2+
3+
__all__ = ("MapAnnotation", "prepare", "resolve_all")
4+
5+
class MapAnnotation:
6+
def __init__(self, d: dict[str, Any]) -> None: ...
7+
def annotate(self, task: Any) -> dict[str, Any] | None: ...
8+
def annotate_any(self) -> dict[str, Any] | None: ...
9+
10+
def prepare(annotations: Any) -> Any: ...
11+
def resolve_all(anno: Any, task: Any) -> dict[str, Any]: ...

celery-stubs/app/autoretry.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from collections.abc import Callable
2+
from typing import Any
3+
4+
def add_autoretry_behaviour(task: Any, **options: Any) -> Callable[..., Any]: ...

celery-stubs/app/backends.pyi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import Any
2+
3+
from celery.backends.base import Backend
4+
5+
__all__ = ("by_name", "by_url")
6+
7+
BACKEND_ALIASES: dict[str, str]
8+
UNKNOWN_BACKEND: str
9+
10+
def by_name(
11+
backend: str | None = None,
12+
loader: Any | None = None,
13+
extension_namespace: str = "celery.result_backends",
14+
) -> type[Backend]: ...
15+
def by_url(backend: str | None = None, loader: Any | None = None) -> type[Backend]: ...

0 commit comments

Comments
 (0)