Re: [PATCH v4 1/2] scripts: generate_rust_analyzer.py: add versioning infrastructure
From: Jesung Yang
Date: Tue Apr 28 2026 - 09:45:36 EST
On Mon, Apr 27, 2026 at 2:23 PM Tamir Duberstein <tamird@xxxxxxxxxx> wrote:
>
> Some options:
>
> ```
> T = t.TypeVar('T')
> if sys.version_info < (3, 10):
> import typing_extensions as te
>
> P = te.ParamSpec('P')
> else:
> P = t.ParamSpec('P')
>
>
> def wrapper(func: t.Callable[P, T]) -> t.Callable[P, T]:
> def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
> return func(*args, **kwargs)
> return wrapper
> ```
>
> This requires typing_extensions, so is not ideal, but mypy passes with
> both --python 3.9 and --python 3.10.
>
> ```
> T = t.TypeVar('T')
> if sys.version_info < (3, 10):
> def wrapper(func: t.Callable[..., T]) -> t.Callable[..., T]:
> def wrapper(*args: t.Any, **kwargs: t.Any) -> T:
> return func(*args, **kwargs)
> return wrapper
> else:
> P = t.ParamSpec('P')
>
> def wrapper(func: t.Callable[P, T]) -> t.Callable[P, T]:
> def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
> return func(*args, **kwargs)
> return wrapper
> ```
>
> This also works and type checks in both versions. Of course, the type
> information is discarded on 3.9, but as long as we run mypy on 3.10 we
> are OK.
I'd go for the latter, since the former would require Python 3.9 users
to install an extra dependency to run `make LLVM=1 rust-analyzer`.
Thanks for the suggestions!
Best regards,
Jesung