Skip to content

"Invalid type" error for Optional[int] alias #3191

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
pgjones opened this issue Apr 18, 2017 · 0 comments
Closed

"Invalid type" error for Optional[int] alias #3191

pgjones opened this issue Apr 18, 2017 · 0 comments
Assignees
Labels
bug mypy got something wrong priority-1-normal

Comments

@pgjones
Copy link

pgjones commented Apr 18, 2017

The following snippet fails with 5: error: Invalid type "T" with mypy 0.501 on Python 3.5.2.

from typing import List, Optional

T = Optional[int]

Ts = []  # type: List[T]

This is similar to #1637 and was originally discussed there.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-1-normal labels Apr 18, 2017
@ilevkivskyi ilevkivskyi self-assigned this Apr 18, 2017
JukkaL pushed a commit that referenced this issue Jul 7, 2017
Fixes #2887. Fixes #3191.

In addition this prohibits reassigning aliases. Previously something like 
this was allowed:

```
if random():
    Alias = Sequence[int]
else:
    Alias = Sequence[float]

def fun(arg: Alias) -> None:
    ...
```

Now this will generate an error: 

    Cannot assign multiple types to name "Alias" without an explicit "Type[...]" 
    annotation. 

See #3494 for background.

Finally, this simplifies the logic in semanal.py, so that most processing of type aliases 
happens in one function.
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-1-normal
Projects
None yet
Development

No branches or pull requests

2 participants