Skip to content

Commit 60d818d

Browse files
committed
Add explicit kwargs to Celery.__init__, _task_from_fun, and Signature.apply_async
Restore explicit keyword arguments for better IDE autocomplete support: - Celery.__init__: Add config kwargs (imports, broker_*, result_*, task_*, worker_*) - Celery._task_from_fun: Add autoretry and task option kwargs - Signature.apply_async: Add options kwargs (task_id, producer, link, countdown, etc.) Use keyword-only syntax (*,) to satisfy stubtest while still providing typed kwargs for IDE support.
1 parent e3460ff commit 60d818d

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

celery-stubs/app/base.pyi

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,44 @@ class Celery(Generic[_T_Global]):
100100
autofinalize: bool = True,
101101
namespace: str | None = None,
102102
strict_typing: bool = True,
103+
*,
104+
# Config kwargs that can be passed directly (captured by **kwargs at runtime)
105+
imports: list[str] | tuple[str, ...] | None = ...,
106+
broker_connection_retry: bool = ...,
107+
broker_connection_max_retries: int = ...,
108+
broker_channel_error_retry: bool = ...,
109+
broker_login_method: str = ...,
110+
broker_transport_options: dict[str, Any] = ...,
111+
broker_connection_retry_on_startup: bool = ...,
112+
broker_connection_timeout: float = ...,
113+
result_backend_transport_options: dict[str, Any] | None = ...,
114+
result_extended: bool = ...,
115+
result_expires: datetime.timedelta = ...,
116+
beat_schedule: dict[str, Any] | None = ...,
117+
task_queues: list[kombu.Queue] | None = ...,
118+
task_default_queue: str = ...,
119+
task_default_exchange: str = ...,
120+
task_default_exchange_type: str = ...,
121+
task_default_routing_key: str = ...,
122+
task_default_delivery_mode: str = ...,
123+
task_create_missing_queues: bool = ...,
124+
task_routes: dict[Any, Any] | Sequence[Any] = ...,
125+
task_acks_late: bool = ...,
126+
task_time_limit: int = ...,
127+
task_soft_time_limit: int = ...,
128+
task_track_started: bool = ...,
129+
task_serializer: str = ...,
130+
worker_prefetch_multiplier: int = ...,
131+
worker_max_tasks_per_child: int = ...,
132+
worker_concurrency: int = ...,
133+
worker_max_memory_per_child: int = ...,
134+
worker_disable_rate_limits: bool = ...,
135+
worker_cancel_long_running_tasks_on_connection_loss: bool = ...,
136+
worker_hijack_root_logger: bool = ...,
137+
worker_log_format: str = ...,
138+
worker_task_log_format: str = ...,
139+
worker_redirect_stdouts: bool = ...,
140+
worker_redirect_stdouts_level: str = ...,
103141
**kwargs: Any,
104142
) -> None: ...
105143
def _task_from_fun(
@@ -108,10 +146,44 @@ class Celery(Generic[_T_Global]):
108146
name: str | None = None,
109147
base: type[_T_Global] | None = None,
110148
bind: bool = False,
149+
# pydantic options (new in celery 5.4+)
111150
pydantic: bool = False,
112151
pydantic_strict: bool = False,
113152
pydantic_context: dict[str, Any] | None = None,
114153
pydantic_dump_kwargs: dict[str, Any] | None = None,
154+
*,
155+
# autoretry options (captured by **options at runtime)
156+
autoretry_for: Sequence[type[BaseException]] = ...,
157+
dont_autoretry_for: Sequence[type[BaseException]] = ...,
158+
retry_kwargs: dict[str, Any] = ...,
159+
retry_backoff: bool | int = ...,
160+
retry_backoff_max: int = ...,
161+
retry_jitter: bool = ...,
162+
# task options
163+
typing: bool = ...,
164+
max_retries: int | None = ...,
165+
default_retry_delay: int = ...,
166+
rate_limit: str | None = ...,
167+
ignore_result: bool = ...,
168+
trail: bool = ...,
169+
send_events: bool = ...,
170+
store_errors_even_if_ignored: bool = ...,
171+
serializer: str = ...,
172+
time_limit: int | None = ...,
173+
soft_time_limit: int | None = ...,
174+
autoregister: bool = ...,
175+
track_started: bool = ...,
176+
acks_late: bool = ...,
177+
acks_on_failure_or_timeout: bool = ...,
178+
reject_on_worker_lost: bool = ...,
179+
throws: tuple[type[Exception], ...] = ...,
180+
expires: float | datetime.datetime | None = ...,
181+
priority: int | None = ...,
182+
resultrepr_maxsize: int = ...,
183+
request_stack: _LocalStack[Context] = ...,
184+
abstract: bool = ...,
185+
after_return: Callable[..., Any] = ...,
186+
on_retry: Callable[..., Any] = ...,
115187
**options: Any,
116188
) -> _T_Global: ...
117189
def on_init(self) -> None: ...

celery-stubs/canvas.pyi

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ class Signature(dict[str, Any], Generic[_R_co]):
8888
args: tuple[Any, ...] | None = ...,
8989
kwargs: dict[str, Any] | None = ...,
9090
route_name: str | None = ...,
91+
*,
92+
# options (captured by **options at runtime)
93+
task_id: str | None = ...,
94+
producer: kombu.Producer | None = ...,
95+
link: Signature[Any] | list[Signature[Any]] | None = ...,
96+
link_error: Signature[Any] | list[Signature[Any]] | None = ...,
97+
shadow: str | None = ...,
98+
# apply_async options
99+
countdown: float = ...,
100+
eta: datetime | None = ...,
101+
expires: float | datetime = ...,
102+
retry: bool = ...,
103+
retry_policy: Mapping[str, Any] = ...,
104+
queue: str | kombu.Queue = ...,
105+
exchange: str | kombu.Exchange = ...,
106+
routing_key: str = ...,
107+
priority: int = ...,
108+
serializer: str = ...,
109+
compression: str = ...,
110+
add_to_parent: bool = ...,
111+
publisher: kombu.Producer = ...,
112+
headers: dict[str, str] = ...,
91113
**options: Any,
92114
) -> celery.result.AsyncResult[_R_co]: ...
93115
def clone(

0 commit comments

Comments
 (0)