-
-
Notifications
You must be signed in to change notification settings - Fork 499
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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.
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.6django
version: 4.2.15mypy
version: 1.11.2django-stubs
version: 5.1.0django-stubs-ext
version: 5.1.0
dbowring, martinlehoux, dmartin, jose-reveni, MrJaeger and 7 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working