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

Mypy treats type aliases of nested classes as invalid types #2075

Closed
Michael0x2a opened this issue Aug 31, 2016 · 1 comment · Fixed by #2868
Closed

Mypy treats type aliases of nested classes as invalid types #2075

Michael0x2a opened this issue Aug 31, 2016 · 1 comment · Fixed by #2868
Labels
bug mypy got something wrong priority-2-low

Comments

@Michael0x2a
Copy link
Collaborator

Consider the following test case:

class Outer:
    class Inner:
        def make_int(self) -> int: return 1

Bar = Outer.Inner
x = Bar()  # type: Bar 
def produce() -> Bar:
    return Bar()

The expected output is for mypy to typecheck this without error, but instead it reports the following:

test.py:6: error: Invalid type "test.Bar"
test.py: note: In function "produce":
test.py:7: error: Invalid type "test.Bar"

As a side-note, I did some brief testing and it seems this error only happens when you use Bar where a type is expected. Mypy is perfectly happy with the following program, for example:

class Outer:
    class Inner:
        def make_int(self) -> int: return 1

Bar = Outer.Inner
x = Bar()  # type: Outer.Inner 
def produce() -> Outer.Inner:
    return Bar()
@Michael0x2a Michael0x2a added the bug mypy got something wrong label Aug 31, 2016
@gvanrossum
Copy link
Member

gvanrossum commented Aug 31, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-2-low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants