modal-labs / synchronicity

Synchronicity lets you interoperate with asynchronous Python APIs.
Apache License 2.0
80 stars 3 forks source link

Fix type stub generation for ParamSpecArgs/Kwargs #172

Closed thecodingwizard closed 1 week ago

thecodingwizard commented 1 week ago

This PR fixes an issue with type stub generations for P.args and P.kwargs when P is a ParamSpec imported from a different module. It also adds a regression test.

This issue came up in https://github.com/modal-labs/modal-client/pull/2319.

Given:

from some_module import P

def foo(fn: typing.Callable[P, None], *args: P.args, **kwargs: P.kwargs) -> str:
    return "Hello World!"

Before (bad):

import some_module

def foo(fn: typing.Callable[some_module.P, None], *args: P.args, **kwargs: P.kwargs) -> str:
    return "Hello World!"

After (good):

import some_module

def foo(fn: typing.Callable[some_module.P, None], *args: some_module.P.args, **kwargs: some_module.P.kwargs) -> str:
    return "Hello World!"