Re: [PATCH] scripts: generate_rust_analyzer.py: reduce import noise
From: Jesung Yang
Date: Tue Apr 28 2026 - 11:10:50 EST
On Mon, Apr 27, 2026 at 2:52 PM Tamir Duberstein <tamird@xxxxxxxxxx> wrote:
>
> Thanks for taking a look. I'm not aware of regular kernel practice in
> this area. This patch is motivated by the discussion in
> https://lore.kernel.org/all/CAJ-ks9=p3i5xbnDojJ7QopmUanec0ZPZ_x3_zD0Csyad5L7FEA@xxxxxxxxxxxxxx/
> where symbols used from `typing` may become conditional, which would
> complicate declaring all the imports at the top.
I'm not aware of the kernel practice either, but if `t.Something` is
unusual in typical Python projects, I think this elaboration deserves to
be mentioned in the commit message.
Other than that, given that declaring all imports at the top is not
mandatory, I wonder if we could just conditionally import `ParamSpec` as
follows:
```
from typing import Any, Callable, TypeVar
T = TypeVar('T')
if sys.version_info < (3, 10):
def wrapper(func: Callable[..., T]) -> Callable[..., T]:
def wrapper(*args: Any, **kwargs: Any) -> T:
return func(*args, **kwargs)
return wrapper
else:
from typing import ParamSpec
P = ParamSpec('P')
def wrapper(func: Callable[P, T]) -> Callable[P, T]:
def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
return func(*args, **kwargs)
return wrapper
```
In this case, we don't need the `t.` prefix.
Best regards,
Jesung