Re: [PATCH v4 1/2] scripts: generate_rust_analyzer.py: add versioning infrastructure
From: Jesung Yang
Date: Mon Apr 27 2026 - 07:14:47 EST
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:
> >
> > The idea was to augment all `append_*` functions with a decorator that
> > contains the `sysroot_deps` logic so that we don't have to call
> > `sysroot_deps` multiple times at the call site. Something like the
> > following (not tested, just for demonstration):
> >
> > -------------------------------------------------
> > def filter_deps(f):
> > def wrapper(*args, **kwargs):
> > args = list(args)
> > args[2] = [dep for dep in args[2] if dep in not None]
> > return f(*args, **kwargs)
> > return wrapper
> >
> > @filter_deps
> > def append_proc_macro_crate(
> > display_name: str,
> > root_module: pathlib.Path,
> > deps: List[Dependency],
> > *,
> > ...,
> > ) -> Dependency:
> > # ...
> >
> > @filter_deps
> > def append_crate(
> > display_name: str,
> > root_module: pathlib.Path,
> > deps: List[Dependency],
> > *,
> > ...,
> > ) -> Dependency:
> > # ...
> > -------------------------------------------------
> >
> > Since this only touches the function definitions, we have fewer
> > things to clean up.
> >
> > Note that this isn't a clean solution: we'd need to keep mypy happy,
> > `deps` isn't always the third parameter, and there's a discrepancy
> > between the written signature and the wrapped behavior (the latter
> > effectively changes the type of `deps` from `List[Dependency]` to
> > `List[Optional[Dependency]]`).
>
> Right, and also the way you've written the decorator won't appease
> mypy; you'll need type annotations. If the goal is to change the type
> of `deps` to a list of optionals, a decorator is a nice way to do that
> without polluting the git history.
>
> I believe the proper way to annotate this kind of decorator is using
> ParamSpec (https://docs.python.org/3/library/typing.html#typing.ParamSpec)
> which might not be supported in Python 3.9. That might be OK though -
> our minimum Python for type checking need not equal our minimum Python
> at runtime.
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?
Best regards,
Jesung