Skip to content

Inheritance from nested class doesn't always work #9239

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

Closed
evhub opened this issue Jul 31, 2020 · 3 comments
Closed

Inheritance from nested class doesn't always work #9239

evhub opened this issue Jul 31, 2020 · 3 comments

Comments

@evhub
Copy link
Contributor

evhub commented Jul 31, 2020

I can't tell if this is the same issue as my previous issue #9238 or not, so I'm raising it separately.

On MyPy 0.780, the code

class B:
    pass

class A:
    B = B

class C(A.B):
    pass

raises

test.py:7: error: Variable "test.A.B" is not valid as a type
test.py:7: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
test.py:7: error: Invalid base class "A.B"
Found 2 errors in 1 file (checked 1 source file)

despite the equivalent code

class A:
    class B:
        pass

class C(A.B):
    pass

working fine.

@evhub evhub changed the title Inheritance from nested class not working Inheritance from nested class doesn't always work Jul 31, 2020
@ilevkivskyi
Copy link
Member

This works as intended. See my comment in #9238

@evhub
Copy link
Contributor Author

evhub commented Aug 3, 2020

@ilevkivskyi Is there any way to annotate the above code that would work (aside from type: ignore)? I'd like to be able to properly type-check that code.

@ilevkivskyi
Copy link
Member

Something that may work is B = Union[B].

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