You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using TypeAlias that includes a TypeVar, the TypeVar results in unknown type
Using the TypeVar directly does not result in the error
Pyright's behavior is correct here, so this isn't a bug.
You're creating a generic type alias that has one type parameter. That means any time you use the type alias, you should provide a single type argument. If you don't provide a type argument, type checkers will assume that you mean Any. This is the same as with generic types. For example, if you use list in a type annotation, a static type checker will assume that you mean list[Any].
You can fix the bug in your code by replacing _DisplayT with _DisplayT[_ModelT] in the generic_func function signature.
If you enable the reportMissingTypeArgument diagnostic rule in pyright, it will tell you when you have omitted a type argument for a generic class or type alias.
If you're using Python 3.12, you can switch to the new type parameter syntax (defined in PEP 695), which is less confusing than the older syntax. Here's how your code looks with the new syntax:
Describe the bug
When using
TypeAlias
that includes aTypeVar
, theTypeVar
results in unknown typeUsing the TypeVar directly does not result in the error
Code or Screenshots
This is a simplified example from django-stubs
_DisplayT
type that produces the same errorVS Code extension or command-line
pyright: 1.1.339
The text was updated successfully, but these errors were encountered: