You should use List[int] (note capital first letter) and similar for other generic types. Please read https://docs.python.org/3/library/typing.html
The fact that this is accepted by PyCharm is a PyCharm bug, and should be reported on their tracker. -- Ivan On 29 April 2017 at 14:32, Edward Ned Harvey (python) <pyt...@nedharvey.com> 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"]): > > print("Ok") > > > > > > 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 > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/ > levkivskyi%40gmail.com > >
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com