-
Notifications
You must be signed in to change notification settings - Fork 141
Closed
astral-sh/ruff
#21553Description
Summary
Having issues when I have a class with multiple type arguments.
I can create some alias if I specify all the type arguments, however, if I leave one as a TypeVar then attempt to create a new alias from this alias, ty doesn't like it.
Mypy and my IDE seem happy with this approach.
from typing import Generic, TypeVar
T = TypeVar("T")
U = TypeVar("U")
class MyClass(Generic[T, U]):
pass
IntStrClass = MyClass[int, str] # This is fine
V = TypeVar("V")
IntAnyClass = MyClass[int, V]
IntStrClass2 = IntAnyClass[str] # This gets non-subscriptable error
W = TypeVar("W")
AnyStrClass = MyClass[W, str]
IntStrClass3 = AnyStrClass[int] # This gets non-subscriptable error
All pyproject.toml settings are default and we're just running a simple ty check.
The obvious workaround is to just have every alias defined directly on MyClass, but it would be nice to allow this sugar as it helps minimize code. And we can use the "partial aliases" throughout the code where we do not know one of the Generic type arguments upfront.
Version
ty 0.0.1-alpha.26 (b225fd8 2025-11-10)
Metadata
Metadata
Assignees
Labels
No labels