-
Notifications
You must be signed in to change notification settings - Fork 2.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 our terms of service and privacy 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 <[email protected]>
dspy/utils/asyncify.py
Outdated
|
|
||
| def asyncify(program: "Module") -> Callable[[Any, Any], Awaitable[Any]]: | ||
| @overload | ||
| def asyncify(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 use ParamSpec and TypeVar 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 to Callable[..., Awaitable[T]].
Changes in commit 4b759b3.
Co-authored-by: TomeHirata <[email protected]>
dspy/utils/asyncify.py
Outdated
|
|
||
|
|
||
| @overload | ||
| def asyncify(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 know T 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. Since Module doesn't have a generic return type, we can't statically determine T. Fixed to use Any instead: Callable[..., Awaitable[Any]].
For typed callables, the signature is preserved: Callable[P, T] → Callable[P, Awaitable[T]].
For Modules, we use Any since the return type varies by implementation.
Changes in commit be2bd89.
Co-authored-by: TomeHirata <[email protected]>
📝 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 more Copilot coding agent tips in the docs.