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
I am trying to define an alias for an annotated model to be used as parameter type for a function header.
class MyModelExtra(TypedDict):
foo: str
type MyModelWithExtra = WithAnnotations[MyModel, MyModelExtra]
OR
MyModelWithExtra: TypeAlias = WithAnnotations[MyModel, MyModelExtra]
WithAnnotations is being flagged by Mypy - stacktrace:
/project/types.py:171:43:171:43: error: Bad number of arguments for type alias, expected 1, given 2 [type-arg]
/project/types.py:171:43:171:43: error: Type application is only supported for generic classes [misc]
I even seem to be getting this error sometimes in places where it's redefined directly as a parameter type rather than an alias. In other words, param: WithAnnotations[MyModel, MyModelExtra]
I've tried defining the type alias in different ways including:
class MyModelWithExtra(WithAnnotations[MyModel, MyModelExtra]):
pass
class MyModelWithExtra(Annotated[MyModel, Annotations[MyModelExtra]]):
pass
Those methods don't throw the error, but it seems the actual annotation gets dropped and the type winds up just resolving to the standard MyModel.
How is that should be
I expect that WithAnnotations would work as an alias or at least redefined directly. I can't tell why Mypy thinks WithAnnotations takes 1 argument instead of 2.
System information
OS: Mac OS 14.7
python version: 3.12.6
django version: 4.2.15
mypy version: 1.11.2
django-stubs version: 5.1.0
django-stubs-ext version: 5.1.0
The text was updated successfully, but these errors were encountered:
Bug report
What's wrong
I am trying to define an alias for an annotated model to be used as parameter type for a function header.
WithAnnotations is being flagged by Mypy - stacktrace:
I even seem to be getting this error sometimes in places where it's redefined directly as a parameter type rather than an alias. In other words,
param: WithAnnotations[MyModel, MyModelExtra]
I've tried defining the type alias in different ways including:
Those methods don't throw the error, but it seems the actual annotation gets dropped and the type winds up just resolving to the standard
MyModel
.How is that should be
I expect that WithAnnotations would work as an alias or at least redefined directly. I can't tell why Mypy thinks
WithAnnotations
takes 1 argument instead of 2.System information
python
version: 3.12.6django
version: 4.2.15mypy
version: 1.11.2django-stubs
version: 5.1.0django-stubs-ext
version: 5.1.0The text was updated successfully, but these errors were encountered: