Skip to content

Commit

Permalink
walk mro for Field set type annotations (#2244)
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile authored Jul 3, 2024
1 parent 91cef35 commit 5e88ed7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy_django_plugin/django/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def get_expected_types(self, api: TypeChecker, model_cls: Type[Model], *, method
def get_field_set_type_from_model_type_info(info: Optional[TypeInfo], field_name: str) -> Optional[MypyType]:
if info is None:
return None
field_node = info.names.get(field_name)
field_node = info.get(field_name)
if field_node is None or not isinstance(field_node.type, Instance):
return None
elif not field_node.type.args:
Expand Down
21 changes: 21 additions & 0 deletions tests/typecheck/models/test_create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@
class Child4(Child1):
value4 = models.IntegerField()
- case: mro_is_walked_for_field_annotations
main: |
from myapp.models import Child
Child.objects.create(dct={"hello": "world"}) # no errors
installed_apps:
- myapp
files:
- path: myapp/__init__.py
- path: myapp/models.py
content: |
from __future__ import annotations
from django.db import models
class JSONField(models.TextField): pass # incomplete
class Base(models.Model):
dct: models.Field[dict[str, str], dict[str, str]] = JSONField()
class Child(Base): pass
- case: optional_id_fields_for_create_is_error_if_not_autofield
main: |
from myapp.models import Publisher, Book
Expand Down

0 comments on commit 5e88ed7

Please sign in to comment.