Skip to content

pyasynq 0.2.0

Choose a tag to compare

@denismaciel denismaciel released this 04 Nov 19:01
· 38 commits to master since this release

Typed SDK

Type checkers now see the whole API. The payload and result types come from each handler's signature.

@app.task("email:send", queue="critical")
async def send(email: Email, ctx: TaskContext) -> dict: ...

send                                   # TaskDef[Email, dict]
info = send.enqueue(Email("a@b.c"))    # TaskInfo[dict]
await send.wait_result(info)           # dict
send.enqueue("a@b.c")                  # error: expected Email
send.enqueue(email, proces_in=60)      # error: unknown option
  • Added stubs for the Rust extension (_core.pyi) and a py.typed marker. TaskInfo, Inspector, Client and the other Rust-backed classes are now fully typed, and stubtest checks the stubs against the compiled module.
  • TaskDef[P, R] is generic over the payload and the result. Both @app.task and @app.task("name", ...) keep these types.
  • Enqueue and task options are typed (EnqueueOptions and TaskOptions), so misspelled or mistyped options are reported.
  • Task states are Literal types, for example in inspector.list_tasks(queue, "retry").
  • TaskInfo[R] can be subscripted at runtime.
  • make lint now runs mypy --strict over the package and a type-assertion test file.

This release changes no runtime behavior.

Install

Download the wheel below (Linux x86_64, CPython ≥ 3.10). On other platforms, build from the source distribution, which needs a Rust toolchain:

pip install pyasynq-0.2.0-cp310-abi3-linux_x86_64.whl