- Notifications
You must be signed in to change notification settings - Fork2.4k
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
base:main
Are you sure you want to change the base?
Conversation
Co-authored-by: TomeHirata <33407409+TomeHirata@users.noreply.github.com>
dspy/utils/asyncify.py Outdated
| defasyncify(program:"Module")->Callable[[Any,Any],Awaitable[Any]]: | ||
| @overload | ||
| defasyncify(program:"Module")->Callable[...,Awaitable[Any]]: ... |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
dspy/utils/asyncify.py Outdated
| @overload | ||
| defasyncify(program:"Module")->Callable[...,Awaitable[T]]: ... |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
Uh oh!
There was an error while loading.Please reload this page.
📝 Changes Description
dspy.asyncifyreturnedCallable[[Any, Any], Awaitable[Any]], incorrectly specifying exactly 2 positional arguments. Pyright raisedreportCallIssueerrors on valid calls:Type Signature Fix:
ParamSpec("P")andTypeVar("T")to preserve function signaturesCallable[P, T]→Callable[P, Awaitable[T]](preserves exact parameter specification)Callable[..., Awaitable[Any]](usesAnysince Module return types cannot be statically determined)@overloaddecorators for better type inference based on input type*args: P.args, **kwargs: P.kwargsand return typeTin innerasync_programfunctionBenefits:
Anyto indicate dynamically-typed returnsTest Coverage:
test_asyncify_with_dspy_modulecovering positional/keyword args✅ Contributor Checklist
None. Backward compatible - existing code continues to work unchanged.
Original prompt
💡 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.