FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Multiple inheritance: Cannot determine type of "X" in base class "Y" error · Issue #2871 · python/mypy · GitHub

Repository navigation

Multiple inheritance: Cannot determine type of "X" in base class "Y" error #2871

Closed

Description

This is probably more of a question than a real issue.

The following code is considered erroneous (tested in Python 3):

class BaseA:
    class Sub:
        pass

class BaseB:
    class Sub:
        pass

class Test(BaseA, BaseB):
    pass

mypy responds with:

…: error: Cannot determine type of 'Sub' in base class 'BaseA'
…: error: Cannot determine type of 'Sub' in base class 'BaseB'

But it doesn't complain if I don't use multiple inheritance:

class BaseA:
    class Sub:
        pass

class BaseB:
    class Sub:
        pass

class Test(BaseA):
    pass

Activity

  1. gvanrossum commented on Feb 15, 2017

    Member
  2. JukkaL commented on Feb 16, 2017

    Collaborator

    Based on the error message, it looks likely that the multiple inheritance validity check doesn't expect to see nested classes and gets confused.

  3. syenchuk commented on Feb 16, 2017

    Author

    I have the impression that it gets confused, because the following code passes without errors:

    class BaseA:
        sub = 1   
    
    class BaseB:
        sub = 1 
    
    class Test(BaseA, BaseB):
        pass

    I don't really understand what's wrong with nested classes.

  4. gvanrossum commented on Feb 16, 2017

    Member

    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.

  5. JukkaL commented on Feb 24, 2017

    Collaborator

    Marked as a bug, because the error message is confusing.

  6. syenchuk commented on Nov 8, 2018

    Author

    As a side note, I stumbled upon this issue by trying to use two different mixins in Django:

    class CreatedDateMixin(models.Model):
        date_created = models.DateTimeField(_("created on"), auto_now_add=True)
    
        class Meta:
            abstract = True
    
    
    class UpdatedDateMixin(models.Model):
        date_updated = models.DateTimeField(_("updated on"), auto_now=True)
    
        class Meta:
            abstract = True
    
    
    class Foo(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.

  7. ilevkivskyi commented on Nov 19, 2018

    Member

    (Raising priority to high since this is a very common idiom in Django.)

  8. ilevkivskyi commented on Nov 19, 2018

    Member

    @mkurnikov you might want to try fixing this.

  9. ilevkivskyi commented on Jan 9, 2019

    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL