Skip to content

Commit 3eb6abb

Browse files
walk mro for Field set type annotations (#18)
Co-authored-by: Anthony Sottile <[email protected]>
1 parent 756f62b commit 3eb6abb

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

mypy_django_plugin/django/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def get_expected_types(self, api: TypeChecker, model_cls: Type[Model], *, method
203203
def get_field_set_type_from_model_type_info(info: Optional[TypeInfo], field_name: str) -> Optional[MypyType]:
204204
if info is None:
205205
return None
206-
field_node = info.names.get(field_name)
206+
field_node = info.get(field_name)
207207
if field_node is None or not isinstance(field_node.type, Instance):
208208
return None
209209
elif not field_node.type.args:

tests/typecheck/models/test_create.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@
6060
class Child4(Child1):
6161
value4 = models.IntegerField()
6262
63+
- case: mro_is_walked_for_field_annotations
64+
main: |
65+
from myapp.models import Child
66+
Child.objects.create(dct={"hello": "world"}) # no errors
67+
installed_apps:
68+
- myapp
69+
files:
70+
- path: myapp/__init__.py
71+
- path: myapp/models.py
72+
content: |
73+
from __future__ import annotations
74+
75+
from django.db import models
76+
77+
class JSONField(models.TextField): pass # incomplete
78+
79+
class Base(models.Model):
80+
dct: models.Field[dict[str, str], dict[str, str]] = JSONField()
81+
82+
class Child(Base): pass
83+
6384
- case: optional_id_fields_for_create_is_error_if_not_autofield
6485
main: |
6586
from myapp.models import Publisher, Book

0 commit comments

Comments
 (0)