Skip to content

Typechecker does not check that "types" are actually types #1231

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
sid-kap opened this issue Feb 22, 2016 · 2 comments
Closed

Typechecker does not check that "types" are actually types #1231

sid-kap opened this issue Feb 22, 2016 · 2 comments
Labels
bug mypy got something wrong

Comments

@sid-kap
Copy link
Contributor

sid-kap commented Feb 22, 2016

MyPy does not show an error for the following code:

import typing

def foo(s: set[int]) -> int:
  return len(s)

def goo(l: list[int]) -> int:
  return len(l)

However, this code is not actually valid: it throws the following error at runtime:

Traceback (most recent call last):
  File "error.py", line 3, in <module>
    def foo(s: set[int]) -> int:
TypeError: 'type' object is not subscriptable

The first step to fixing this code is to change set to Set and list to List. This, however, leads to another runtime error:

Traceback (most recent call last):
  File "error.py", line 3, in <module>
    def foo(s: Set[int]) -> int:
NameError: name 'Set' is not defined

Finally, we need to add the following imports:

from typing import Set, List

and the program finally runs without an error.

So there are two issues here:

  1. mypy should catch when a "not subscriptable" thing (whatever that means) is written instead of an actual type
  2. mypy should detect when types are used without being imported
@JukkaL JukkaL added the bug mypy got something wrong label Feb 22, 2016
@JukkaL
Copy link
Collaborator

JukkaL commented Feb 22, 2016

Yeah, these are (known) bugs. I'm not sure if there is another issue created for this.

I believe that this only affects List, Dict and Set because they are special cased as aliases to list, dict and set, respectively. Mypy should not consider List and list interchangeable, as it currently does. However, list should still remain a valid type and be equivalent to List[Any].

@gvanrossum
Copy link
Member

This is probably a dupe of #999.

@gnprice gnprice modified the milestone: 0.3.2 Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

4 participants