ITADN

`WithAnnotations` raises `TypeError` when evaluated at runtime

#3423Closedmilssky 创建于 2026-06-10
bug
M
milsskycommented
# Bug report <!-- Hi, thanks for submitting a bug. We appreciate that. But, we will need some information about what's wrong to help you. --> ## What's wrong The documented `WithAnnotations[Model, TypedDict]` syntax works with mypy but raises `TypeError` when evaluated at runtime. Repro code ```python from typing import TypeAlias, TypedDict from django.db.models import Model, QuerySet from django_stubs_ext import WithAnnotations class ExtraAttrs(TypedDict): count: int AnnotatedQuerySet: TypeAlias = QuerySet[ WithAnnotations[Model, ExtraAttrs] ] ``` Run it from `runserver`, direct with python, from some worker reproduce error ``` TypeError: Too many arguments for typing.Annotated[~_T, django_stubs_ext.annotations.Annotations[+_Annotations]]; actual 2, expected 1 ``` ## How is that should be <!-- Describe how it should work. --> The module should import successfully. `WithAnnotations` should support its documented two-argument form at runtime as well as during static type checking. Workaround Using a string as the alias value prevents runtime evaluation: ```python AnnotatedQuerySet: TypeAlias = ( "QuerySet[WithAnnotations[Model, ExtraAttrs]]" ) ``` ## System information - OS: macos tahoe 26.5 - `python` version: 3.13.11 - `django` version: 6.0.6 - `mypy` version: 2.1.0 - `django-stubs` version: - `django-stubs-ext` version:
关闭于 2026-06-10 3 条评论