Skip to content

[Bug] dspy.asyncify triggers Pyright "reportCallIssue" type error #9058

@ekthaacc

Description

@ekthaacc

What happened?

When using dspy.asyncify to convert a DSPy module into an async callable, Pyright raises a reportCallIssue type error even though the asyncified module runs correctly at runtime.
As a result, static type-checking fails locally and in CI pipelines, which breaks builds that enforce type-safety.

Expected behaviour:

Pyright should not raise a type error; the asyncified module should be recognized as a callable with the same argument signature as the original module.

Environment:

Python: 3.12
DSPy==3.0.3
Pyright==1.1.407
OS: Mac

Possible Cause:

dspy.asyncify wraps the module dynamically without preserving its original type annotations.
Pyright then infers an incomplete or incorrect callable signature, leading to the diagnostic.

Suggested Fix:

Update the type signature of dspy.asyncify to use typing.ParamSpec and typing.TypeVar.
This will allow the function to preserve the original module’s argument types and annotations and correctly re-type the return value as a coroutine (e.g., Awaitable[T]).

Current Workaround:

`from typing import Callable, Awaitable, Any, cast

dspy_module_async = cast("Callable[..., Awaitable[Any]]", dspy.asyncify(dspy_module))
`

Steps to reproduce

`import dspy

class MyModule(dspy.Module):
def forward(self, x):
return x * 2

optimized_module = MyModule()
optimized_module_async = dspy.asyncify(optimized_module)

Pyright error here:
error: Expected 2 positional arguments (reportCallIssue)

result = await optimized_module_async(5)
`

DSPy version

3.0.3

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions