You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After running on an internal codebase, where we have a few places using inherited models, I encountered some issues in figuring out the correct Manager type for an inherited Model (which otherwise works great!), when there is an import cycle.
I created a relatively small testcase that demonstrates the problem:
[CASE managers_multiple_inheritance_multiple_files_import_cycle]
from django.db import models
from myapp.models import Child
reveal_type(Child.objects) # E: Revealed type is 'django.db.models.manager.Manager[myapp.models.child.Child]'
Child.objects.create(c=True, p="abc", other_id=123)
[file myapp/__init__.py]
[file myapp/models/__init__.py]
from .other import Other
from .parent import Parent
from .child import Child
[file myapp/models/other.py]
from django.db import models
class Other(models.Model):
o = models.CharField(max_length=255)
[file myapp/models/parent.py]
from django.db import models
from myapp.models import Other
# Changing the above line to the following fixes around the problem:
#from myapp.models.other import Other
class Parent(models.Model):
p = models.CharField(max_length=255)
other = models.ForeignKey(Other, on_delete=models.CASCADE)
[file myapp/models/child.py]
from django.db import models
from myapp.models import Parent
class Child(Parent):
c = models.BooleanField(default=True)
reveal_type(Child.objects) gives: Revealed type is 'django.db.models.manager.Manager[myapp.models.parent.Parent]'
But it should be django.db.models.manager.Manager[myapp.models.child.Child].
If I change the line from myapp.models import Other to from myapp.models.other import Other in myapp/models/parent.py, then it behaves as expected, so there is a fairly easy workaround.
I don't know if this is something to do with mypy itself or how this plugin works.
The text was updated successfully, but these errors were encountered:
After running on an internal codebase, where we have a few places using inherited models, I encountered some issues in figuring out the correct Manager type for an inherited Model (which otherwise works great!), when there is an import cycle.
I created a relatively small testcase that demonstrates the problem:
reveal_type(Child.objects)
gives:Revealed type is 'django.db.models.manager.Manager[myapp.models.parent.Parent]'
But it should be
django.db.models.manager.Manager[myapp.models.child.Child]
.If I change the line
from myapp.models import Other
tofrom myapp.models.other import Other
inmyapp/models/parent.py
, then it behaves as expected, so there is a fairly easy workaround.I don't know if this is something to do with mypy itself or how this plugin works.
The text was updated successfully, but these errors were encountered: