Skip to content

"Cannot determine type" on inner class inheritance #5914

Closed

Description

@mthuurne

I run mypy on the following code, with no arguments other than the file name:

class InnerBase:
    pass

class OuterBase:
    class Inner(InnerBase):
        pass

class OuterMixin:
    class Inner(InnerBase):
        pass

class Outer(OuterBase, OuterMixin):
    pass

The output that I get is as follows:

inner.py:12: error: Cannot determine type of 'Inner' in base class 'OuterBase'
inner.py:12: error: Cannot determine type of 'Inner' in base class 'OuterMixin'

Line 12 is the line that starts with class Outer.

I don't understand why the types cannot be determined: Type[OuterBase.Inner] and Type[OuterMixin.Inner] respectively would be the types for the inner classes, I think.

Note that the errors go away when Outer inherits only from OuterBase or only from OuterMixin.

I'm using mypy 0.641 on Python 3.6.5.

Activity

  1. ilevkivskyi commented on Nov 19, 2018

    @ilevkivskyi
    Member

    Duplicate of #2871

    (As a side note this is still technically not type safe, this is like you would a have multiple inheritance with inner: str and inner: int in two bases.)

  2. mthuurne commented on Nov 19, 2018

    @mthuurne
    ContributorAuthor

    Sorry for opening a duplicate; neither the manual search I did nor the GitHub "related issues" beta function turned up the existing report.

    This minimal test case leaves out some details that the production code uses. Even so, I think it's type-safe as long as the Outer class will only use Inner according to the InnerBase interface.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions