|
8 | 8 |
|
9 | 9 | unannotated_user = User.objects.get(id=1)
|
10 | 10 |
|
11 |
| - print(annotated_user.asdf) # E: "WithAnnotations[myapp.models.User, TypedDict({'foo': Any})]" has no attribute "asdf" |
| 11 | + print(annotated_user.asdf) # E: "WithAnnotations[myapp__models__User, TypedDict({'foo': Any})]" has no attribute "asdf" |
12 | 12 | print(unannotated_user.asdf) # E: "User" has no attribute "asdf"
|
13 | 13 |
|
14 | 14 | def func(user: Annotated[User, Annotations]) -> str:
|
15 | 15 | return user.asdf
|
16 | 16 |
|
17 |
| - func(unannotated_user) # E: Argument 1 to "func" has incompatible type "User"; expected "WithAnnotations[myapp.models.User]" |
18 |
| - func(annotated_user) # E: Argument 1 to "func" has incompatible type "WithAnnotations[myapp.models.User, TypedDict({'foo': Any})]"; expected "WithAnnotations[myapp.models.User]" |
| 17 | + func(unannotated_user) # E: Argument 1 to "func" has incompatible type "User"; expected "WithAnnotations[myapp__models__User]" |
| 18 | + func(annotated_user) # E: Argument 1 to "func" has incompatible type "WithAnnotations[myapp__models__User, TypedDict({'foo': Any})]"; expected "WithAnnotations[myapp__models__User]" |
19 | 19 |
|
20 | 20 | def func2(user: WithAnnotations[User]) -> str:
|
21 | 21 | return user.asdf
|
22 | 22 |
|
23 |
| - func2(unannotated_user) # E: Argument 1 to "func2" has incompatible type "User"; expected "WithAnnotations[myapp.models.User]" |
24 |
| - func2(annotated_user) # E: Argument 1 to "func2" has incompatible type "WithAnnotations[myapp.models.User, TypedDict({'foo': Any})]"; expected "WithAnnotations[myapp.models.User]" |
| 23 | + func2(unannotated_user) # E: Argument 1 to "func2" has incompatible type "User"; expected "WithAnnotations[myapp__models__User]" |
| 24 | + func2(annotated_user) # E: Argument 1 to "func2" has incompatible type "WithAnnotations[myapp__models__User, TypedDict({'foo': Any})]"; expected "WithAnnotations[myapp__models__User]" |
25 | 25 | installed_apps:
|
26 | 26 | - myapp
|
27 | 27 | files:
|
|
44 | 44 | foo: str
|
45 | 45 |
|
46 | 46 | def func(user: Annotated[User, Annotations[MyDict]]) -> str:
|
47 |
| - print(user.asdf) # E: "WithAnnotations[myapp.models.User, TypedDict('main.MyDict', {'foo': builtins.str})]" has no attribute "asdf" |
| 47 | + print(user.asdf) # E: "WithAnnotations[myapp__models__User, TypedDict('main.MyDict', {'foo': builtins.str})]" has no attribute "asdf" |
48 | 48 | return user.foo
|
49 | 49 |
|
50 | 50 | unannotated_user = User.objects.get(id=1)
|
51 | 51 | annotated_user = User.objects.annotate(foo=Value("")).get()
|
52 | 52 | other_annotated_user = User.objects.annotate(other=Value("")).get()
|
53 | 53 |
|
54 |
| - func(unannotated_user) # E: Argument 1 to "func" has incompatible type "User"; expected "WithAnnotations[myapp.models.User, TypedDict('main.MyDict', {'foo': builtins.str})]" |
| 54 | + func(unannotated_user) # E: Argument 1 to "func" has incompatible type "User"; expected "WithAnnotations[myapp__models__User, TypedDict('main.MyDict', {'foo': builtins.str})]" |
55 | 55 | x: WithAnnotations[User]
|
56 | 56 | func(x)
|
57 | 57 | func(annotated_user)
|
58 |
| - func(other_annotated_user) # E: Argument 1 to "func" has incompatible type "WithAnnotations[myapp.models.User, TypedDict({'other': Any})]"; expected "WithAnnotations[myapp.models.User, TypedDict('main.MyDict', {'foo': builtins.str})]" |
| 58 | + func(other_annotated_user) # E: Argument 1 to "func" has incompatible type "WithAnnotations[myapp__models__User, TypedDict({'other': Any})]"; expected "WithAnnotations[myapp__models__User, TypedDict('main.MyDict', {'foo': builtins.str})]" |
59 | 59 |
|
60 | 60 | def func2(user: WithAnnotations[User, MyDict]) -> str:
|
61 |
| - print(user.asdf) # E: "WithAnnotations[myapp.models.User, TypedDict('main.MyDict', {'foo': builtins.str})]" has no attribute "asdf" |
| 61 | + print(user.asdf) # E: "WithAnnotations[myapp__models__User, TypedDict('main.MyDict', {'foo': builtins.str})]" has no attribute "asdf" |
62 | 62 | return user.foo
|
63 | 63 |
|
64 |
| - func2(unannotated_user) # E: Argument 1 to "func2" has incompatible type "User"; expected "WithAnnotations[myapp.models.User, TypedDict('main.MyDict', {'foo': builtins.str})]" |
| 64 | + func2(unannotated_user) # E: Argument 1 to "func2" has incompatible type "User"; expected "WithAnnotations[myapp__models__User, TypedDict('main.MyDict', {'foo': builtins.str})]" |
65 | 65 | func2(annotated_user)
|
66 |
| - func2(other_annotated_user) # E: Argument 1 to "func2" has incompatible type "WithAnnotations[myapp.models.User, TypedDict({'other': Any})]"; expected "WithAnnotations[myapp.models.User, TypedDict('main.MyDict', {'foo': builtins.str})]" |
| 66 | + func2(other_annotated_user) # E: Argument 1 to "func2" has incompatible type "WithAnnotations[myapp__models__User, TypedDict({'other': Any})]"; expected "WithAnnotations[myapp__models__User, TypedDict('main.MyDict', {'foo': builtins.str})]" |
67 | 67 | installed_apps:
|
68 | 68 | - myapp
|
69 | 69 | files:
|
|
100 | 100 | func(y)
|
101 | 101 |
|
102 | 102 | z: WithAnnotations[User, OtherDict]
|
103 |
| - func(z) # E: Argument 1 to "func" has incompatible type "WithAnnotations[myapp.models.User, TypedDict('main.OtherDict', {'other': builtins.str})]"; expected "WithAnnotations[myapp.models.User, TypedDict('main.NarrowDict', {'foo': builtins.str})]" |
| 103 | + func(z) # E: Argument 1 to "func" has incompatible type "WithAnnotations[myapp__models__User, TypedDict('main.OtherDict', {'other': builtins.str})]"; expected "WithAnnotations[myapp__models__User, TypedDict('main.NarrowDict', {'foo': builtins.str})]" |
104 | 104 |
|
105 | 105 | installed_apps:
|
106 | 106 | - myapp
|
|
119 | 119 | from django.db.models.expressions import F
|
120 | 120 |
|
121 | 121 | qs = User.objects.annotate(foo=F('id'))
|
122 |
| - reveal_type(qs) # N: Revealed type is "django.db.models.query._QuerySet[django_stubs_ext.WithAnnotations[myapp.models.User, TypedDict({'foo': Any})], django_stubs_ext.WithAnnotations[myapp.models.User, TypedDict({'foo': Any})]]" |
| 122 | + reveal_type(qs) # N: Revealed type is "django.db.models.query._QuerySet[django_stubs_ext.WithAnnotations[myapp__models__User, TypedDict({'foo': Any})], django_stubs_ext.WithAnnotations[myapp__models__User, TypedDict({'foo': Any})]]" |
123 | 123 |
|
124 | 124 | annotated = qs.get()
|
125 |
| - reveal_type(annotated) # N: Revealed type is "django_stubs_ext.WithAnnotations[myapp.models.User, TypedDict({'foo': Any})]*" |
| 125 | + reveal_type(annotated) # N: Revealed type is "django_stubs_ext.WithAnnotations[myapp__models__User, TypedDict({'foo': Any})]*" |
126 | 126 | reveal_type(annotated.foo) # N: Revealed type is "Any"
|
127 |
| - print(annotated.bar) # E: "WithAnnotations[myapp.models.User, TypedDict({'foo': Any})]" has no attribute "bar" |
| 127 | + print(annotated.bar) # E: "WithAnnotations[myapp__models__User, TypedDict({'foo': Any})]" has no attribute "bar" |
128 | 128 | reveal_type(annotated.username) # N: Revealed type is "builtins.str*"
|
129 | 129 |
|
130 | 130 | installed_apps:
|
|
144 | 144 | from django.db.models import Count
|
145 | 145 |
|
146 | 146 | qs = User.objects.annotate(Count('id'))
|
147 |
| - reveal_type(qs) # N: Revealed type is "django.db.models.query._QuerySet[django_stubs_ext.WithAnnotations[myapp.models.User], django_stubs_ext.WithAnnotations[myapp.models.User]]" |
| 147 | + reveal_type(qs) # N: Revealed type is "django.db.models.query._QuerySet[django_stubs_ext.WithAnnotations[myapp__models__User], django_stubs_ext.WithAnnotations[myapp__models__User]]" |
148 | 148 |
|
149 | 149 | installed_apps:
|
150 | 150 | - myapp
|
|
167 | 167 | def animals_only(param: Animal):
|
168 | 168 | pass
|
169 | 169 | # Make sure that even though attr access falls back to Any, the type is still checked
|
170 |
| - animals_only(annotated_user) # E: Argument 1 to "animals_only" has incompatible type "WithAnnotations[myapp.models.User]"; expected "Animal" |
| 170 | + animals_only(annotated_user) # E: Argument 1 to "animals_only" has incompatible type "WithAnnotations[myapp__models__User]"; expected "Animal" |
171 | 171 |
|
172 | 172 | def users_allowed(param: User):
|
173 | 173 | # But this function accepts only the original User type, so any attr access is not allowed within this function
|
|
196 | 196 | qs = User.objects.annotate(foo=F('id'))
|
197 | 197 | qs = qs.annotate(bar=F('id'))
|
198 | 198 | annotated = qs.get()
|
199 |
| - reveal_type(annotated) # N: Revealed type is "django_stubs_ext.WithAnnotations[myapp.models.User, TypedDict({'foo': Any, 'bar': Any})]*" |
| 199 | + reveal_type(annotated) # N: Revealed type is "django_stubs_ext.WithAnnotations[myapp__models__User, TypedDict({'foo': Any, 'bar': Any})]*" |
200 | 200 | reveal_type(annotated.foo) # N: Revealed type is "Any"
|
201 | 201 | reveal_type(annotated.bar) # N: Revealed type is "Any"
|
202 | 202 | reveal_type(annotated.username) # N: Revealed type is "builtins.str*"
|
|
227 | 227 | return qs.annotate(foo=F('id'))
|
228 | 228 |
|
229 | 229 | def add_wrong_annotation(qs: QuerySet[User]) -> QuerySet[WithAnnotations[User, FooDict]]:
|
230 |
| - return qs.annotate(bar=F('id')) # E: Incompatible return value type (got "_QuerySet[WithAnnotations[myapp.models.User, TypedDict({'bar': Any})], WithAnnotations[myapp.models.User, TypedDict({'bar': Any})]]", expected "_QuerySet[WithAnnotations[myapp.models.User, TypedDict('main.FooDict', {'foo': builtins.str})], WithAnnotations[myapp.models.User, TypedDict('main.FooDict', {'foo': builtins.str})]]") |
| 230 | + return qs.annotate(bar=F('id')) # E: Incompatible return value type (got "_QuerySet[WithAnnotations[myapp__models__User, TypedDict({'bar': Any})], WithAnnotations[myapp__models__User, TypedDict({'bar': Any})]]", expected "_QuerySet[WithAnnotations[myapp__models__User, TypedDict('main.FooDict', {'foo': builtins.str})], WithAnnotations[myapp__models__User, TypedDict('main.FooDict', {'foo': builtins.str})]]") |
231 | 231 |
|
232 | 232 | qs = add_annotation(qs)
|
233 | 233 | qs.get().foo
|
234 |
| - qs.get().bar # E: "WithAnnotations[myapp.models.User, TypedDict('main.FooDict', {'foo': builtins.str})]" has no attribute "bar" |
| 234 | + qs.get().bar # E: "WithAnnotations[myapp__models__User, TypedDict('main.FooDict', {'foo': builtins.str})]" has no attribute "bar" |
235 | 235 |
|
236 | 236 | installed_apps:
|
237 | 237 | - myapp
|
|
0 commit comments