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

Forward reference to typing.List results in Any #4687

Closed
JukkaL opened this issue Mar 6, 2018 · 4 comments
Closed

Forward reference to typing.List results in Any #4687

JukkaL opened this issue Mar 6, 2018 · 4 comments
Labels
bug mypy got something wrong priority-0-high semantic-analyzer Problems that happen during semantic analysis

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Mar 6, 2018

The revealed type in the program below is Any, which is unexpected:

class A:
    x: List[int]  # Note forward reference to List

reveal_type(A().x)  # Any (should be List[int])

from typing import List

This happens quite a few times in an internal Dropbox codebase in generated stubs.

@JukkaL JukkaL added bug mypy got something wrong priority-0-high labels Mar 6, 2018
@JukkaL JukkaL self-assigned this Mar 6, 2018
@miedzinski
Copy link
Contributor

Actually it should raise an error after #686 is resolved, right?

@JukkaL
Copy link
Collaborator Author

JukkaL commented Mar 8, 2018

Yes, in the original example. When using type comments it should work (or function-local type annotations which aren't evaluated). Here's a better example:

class A:
    def f(self): 
        # type: () -> List[int]  # Note forward reference to List
        return []

reveal_type(A().f)  # Should match () -> List[int]

from typing import List

@JukkaL
Copy link
Collaborator Author

JukkaL commented May 21, 2019

This works correctly with the new semantic analyzer.

@JukkaL JukkaL added the semantic-analyzer Problems that happen during semantic analysis label May 21, 2019
@JukkaL JukkaL removed their assignment May 21, 2019
@JukkaL
Copy link
Collaborator Author

JukkaL commented Jun 11, 2019

Closing this issue since it works correctly with the new semantic analyzer (which we are planning to publicly announce soon).

@JukkaL JukkaL closed this as completed Jun 11, 2019
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-0-high semantic-analyzer Problems that happen during semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants