Re: [PATCH v4 1/2] scripts: generate_rust_analyzer.py: add versioning infrastructure
From: Tamir Duberstein
Date: Mon Apr 27 2026 - 10:27:22 EST
On Mon, Apr 27, 2026 at 7:14 AM Jesung Yang <y.j3ms.n@xxxxxxxxx> wrote:
>
> On Sun, Apr 26, 2026 at 1:50 PM Tamir Duberstein <tamird@xxxxxxxxxx> wrote:
> > On Sun, Apr 26, 2026 at 8:42 AM Jesung Yang <y.j3ms.n@xxxxxxxxx> wrote:
> [...]
>
> I've experimented with `ParamSpec`, but it seems we can't use it in 3.9.
> If I understand correctly, neither `from typing import ParamSpec` nor
> the `def func[**P]` syntax is available in Python 3.9, and both cause
> runtime crashes. Could you elaborate on what you have in mind?
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.