I think just the error is a bit confusing; in the M.I. case it is trying to
point out that you are inheriting two unrelated class attributes named
'Sub'.
Well, for one thing, two integers always have the same type. But two independently declared classes (even if they have the same name and contents) are not considered to have the same type.
As a side note, I stumbled upon this issue by trying to use two different mixins in Django:
classCreatedDateMixin(models.Model):
date_created=models.DateTimeField(_("created on"), auto_now_add=True)
classMeta:
abstract=TrueclassUpdatedDateMixin(models.Model):
date_updated=models.DateTimeField(_("updated on"), auto_now=True)
classMeta:
abstract=TrueclassFoo(CreatedDateMixin, UpdatedDateMixin, models.Model):
name=models.CharField(_("name"), max_length=255, blank=True)
# error: Cannot determine type of 'Meta' in base class 'CreatedDateMixin'# error: Cannot determine type of 'Meta' in base class 'UpdatedDateMixin'
Not exactly a bug, but I don't know how to fix this… And I feel like others might easily stumble upon this issue as well.
Note that mypy still emits an error on the original example, because it is technically unsafe. Note however that @mkurnikov works on a mypy plugin for Django that will suppress this error for Django specific use cases.
Activity
gvanrossum commented on Feb 15, 2017
JukkaL commented on Feb 16, 2017
Based on the error message, it looks likely that the multiple inheritance validity check doesn't expect to see nested classes and gets confused.
syenchuk commented on Feb 16, 2017
I have the impression that it gets confused, because the following code passes without errors:
I don't really understand what's wrong with nested classes.
gvanrossum commented on Feb 16, 2017
Well, for one thing, two integers always have the same type. But two independently declared classes (even if they have the same name and contents) are not considered to have the same type.
JukkaL commented on Feb 24, 2017
Marked as a bug, because the error message is confusing.
syenchuk commented on Nov 8, 2018
As a side note, I stumbled upon this issue by trying to use two different mixins in Django:
Not exactly a bug, but I don't know how to fix this… And I feel like others might easily stumble upon this issue as well.
ilevkivskyi commented on Nov 19, 2018
(Raising priority to high since this is a very common idiom in Django.)
ilevkivskyi commented on Nov 19, 2018
@mkurnikov you might want to try fixing this.
Make error messages from multiple inheritance compatibility check mor…
ilevkivskyi commented on Jan 9, 2019
Note that mypy still emits an error on the original example, because it is technically unsafe. Note however that @mkurnikov works on a mypy plugin for Django that will suppress this error for Django specific use cases.