You should use List[int] (note capital first letter) and similar for other generic types.
Please read

The fact that this is accepted by PyCharm is a PyCharm bug, and should be reported on their tracker.


On 29 April 2017 at 14:32, Edward Ned Harvey (python) <> wrote:

Years ago, I fell in love with python and left C an C++ behind. Sometime later, I fell in love with C# because with strong typing, my IDE does most of the work for me - I never have to browse the API to find which method or attribute exists in a class, I can use tab completion for everything, avoid type-o's, etc. So I was recently thrilled to discover type hinting in python, and support included in pycharm. I'm coming back to python now (for the last few months).


In python 3.6.1, and pycharm CE 2017.1.1 on windows (I haven't tested other versions or other platforms):


The following is recognized and supported by pycharm, but then at runtime, python throws an exception:


                #!/usr/bin/env python3


                def foo(bars: list[str]):

                                for bar in bars:

                                                if bar.startswith("hi"):

                                                                raise ValueError("bar should never say hi")

                                return True



                if foo(["a","b","c"]):




                TypeError: 'type' object is not subscriptable


The problem is that python doesn't recognize list[str] as a type. Pycharm handles it, and everything works fine if I'm using a non-subscripted type, like plain old int, or str, or anything else.


Is this a bug, or is it something python simply hasn't implemented yet, or is it something that's not going to be implemented?


Is there a workaround?

Python-Dev mailing list