Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(dspy): asyncify type signature causing Pyright reportCallIssue#9065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge4 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-pyright-reportcallissue-error

Conversation

Copy link
Contributor

CopilotAI commentedNov 17, 2025
edited
Loading

📝 Changes Description

dspy.asyncify returnedCallable[[Any, Any], Awaitable[Any]], incorrectly specifying exactly 2 positional arguments. Pyright raisedreportCallIssue errors on valid calls:

module=MyModule()async_module=dspy.asyncify(module)result=awaitasync_module(5)# error: Expected 2 positional arguments

Type Signature Fix:

  • AddedParamSpec("P") andTypeVar("T") to preserve function signatures
  • For generic callables:Callable[P, T]Callable[P, Awaitable[T]] (preserves exact parameter specification)
  • For DSPy Modules:Callable[..., Awaitable[Any]] (usesAny since Module return types cannot be statically determined)
  • Added@overload decorators for better type inference based on input type
  • Typed*args: P.args, **kwargs: P.kwargs and return typeT in innerasync_program function

Benefits:

  • Type checkers now know the exact signature of asyncified functions
  • Parameter names, types, and defaults are all preserved for typed callables
  • Incorrect arguments are caught at type-check time, not runtime
  • Module overload correctly usesAny to indicate dynamically-typed returns

Test Coverage:

  • Addedtest_asyncify_with_dspy_module covering positional/keyword args
  • Validates both DSPy modules and plain functions

✅ Contributor Checklist

  • Pre-Commit checks are passing (locally and remotely)
  • Title of your PR / MR corresponds to the required format
  • Commit message follows required format {label}(dspy): {message}

⚠️ Warnings

None. Backward compatible - existing code continues to work unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] dspy.asyncify triggers Pyright "reportCallIssue" type error</issue_title>
<issue_description>### 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</issue_description>

Comments on the Issue (you are@copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.

Co-authored-by: TomeHirata <33407409+TomeHirata@users.noreply.github.com>
CopilotAI changed the title[WIP] Fix Pyright reportCallIssue type error in dspy.asyncifyfix(dspy): asyncify type signature causing Pyright reportCallIssueNov 17, 2025
Copilot finished work on behalf ofTomeHirataNovember 17, 2025 07:17

defasyncify(program:"Module")->Callable[[Any,Any],Awaitable[Any]]:
@overload
defasyncify(program:"Module")->Callable[...,Awaitable[Any]]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@copilot can we use generic typing to keep the function signature?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes! Updated to useParamSpec andTypeVar to preserve function signatures. Now when you pass a typed callable, the asyncified version maintains the exact parameter specification and return type:Callable[P, T]Callable[P, Awaitable[T]]. For DSPy Modules, it falls back toCallable[..., Awaitable[T]].

Changes in commit4b759b3.

Co-authored-by: TomeHirata <33407409+TomeHirata@users.noreply.github.com>
Copilot finished work on behalf ofTomeHirataNovember 17, 2025 07:42


@overload
defasyncify(program:"Module")->Callable[...,Awaitable[T]]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@copilot how can we knowT in this case?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good catch!T was unbound in the Module overload. SinceModule doesn't have a generic return type, we can't statically determineT. Fixed to useAny instead:Callable[..., Awaitable[Any]].

For typed callables, the signature is preserved:Callable[P, T]Callable[P, Awaitable[T]].
For Modules, we useAny since the return type varies by implementation.

Changes in commitbe2bd89.

Co-authored-by: TomeHirata <33407409+TomeHirata@users.noreply.github.com>
Copilot finished work on behalf ofTomeHirataNovember 17, 2025 08:28
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@TomeHirataTomeHirataAwaiting requested review from TomeHirata

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

2 participants

@TomeHirata

[8]ページ先頭

©2009-2025 Movatter.jp