Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot determine type" on inner class inheritance #5914

Closed
mthuurne opened this issue Nov 19, 2018 · 2 comments
Closed

"Cannot determine type" on inner class inheritance #5914

mthuurne opened this issue Nov 19, 2018 · 2 comments

Comments

@mthuurne
Copy link
Contributor

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.

@ilevkivskyi
Copy link
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.)

@mthuurne
Copy link
Contributor Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants