Skip to content

Commit

Permalink
Include ModelBase subclasses in plugin base class hook condition (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaeppe committed Dec 8, 2023
1 parent a1b1f51 commit a0eb714
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy_django_plugin/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,4 @@ def resolve_lazy_reference(


def is_model_type(info: TypeInfo) -> bool:
return info.metaclass_type is not None and info.metaclass_type.type.fullname == fullnames.MODEL_METACLASS_FULLNAME
return info.metaclass_type is not None and info.metaclass_type.type.has_base(fullnames.MODEL_METACLASS_FULLNAME)
22 changes: 22 additions & 0 deletions tests/typecheck/models/test_metaclass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,25 @@
class Concrete3(Concrete2):
...
- case: test_custom_model_base_metaclass
main: |
from myapp.models import This, Other
this = This(field=Other())
reveal_type(this.field) # N: Revealed type is "myapp.models.Other"
installed_apps:
- myapp
files:
- path: myapp/__init__.py
- path: myapp/models.py
content: |
from django.db import models
from django.db.models.base import ModelBase
class MyBase(ModelBase): ...
class MyModel(models.Model, metaclass=MyBase): ...
class Other(MyModel): ...
class This(MyModel):
field = models.ForeignKey(Other, on_delete=models.CASCADE)

0 comments on commit a0eb714

Please sign in to comment.