Showing content from http://mail.python.org/pipermail/python-dev/attachments/20170429/084f607b/attachment.html below:
<div dir="ltr"><div><div><div>You should use List[int] (note capital first letter) and similar for other generic types.<br></div>Please read <a href="https://docs.python.org/3/library/typing.html">https://docs.python.org/3/library/typing.html</a><br><br></div>The fact that this is accepted by PyCharm is a PyCharm bug, and should be reported on their tracker.<br><br>--<br></div>Ivan<br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On 29 April 2017 at 14:32, Edward Ned Harvey (python) <span dir="ltr"><<a href="mailto:python@nedharvey.com" target="_blank">python@nedharvey.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="#0563C1" vlink="#954F72" lang="EN-US">
<div class="m_-2865256241629797566WordSection1">
<p class="MsoNormal">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).<u></u><u></u></p>
<p class="MsoNormal"><u></u>Â <u></u></p>
<p class="MsoNormal">In python 3.6.1, and pycharm CE 2017.1.1 on windows (I haven't tested other versions or other platforms):<u></u><u></u></p>
<p class="MsoNormal"><u></u>Â <u></u></p>
<p class="MsoNormal">The following is recognized and supported by pycharm, but then at runtime, python throws an exception:<u></u><u></u></p>
<p class="MsoNormal"><u></u>Â <u></u></p>
<p class="MsoNormal">Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â #!/usr/bin/env python3<u></u><u></u></p>
<p class="MsoNormal"><u></u>Â <u></u></p>
<p class="MsoNormal">Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â def foo(bars: list[str]):<u></u><u></u></p>
<p class="MsoNormal">Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <wbr>Â for bar in bars:<u></u><u></u></p>
<p class="MsoNormal">Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <wbr>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if bar.startswith("hi"):<u></u><u></u></p>
<p class="MsoNormal">Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <wbr>Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <wbr>Â Â Â raise ValueError("bar should never say hi")<u></u><u></u></p>
<p class="MsoNormal">Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <wbr>Â return True<u></u><u></u></p>
<p class="MsoNormal"><u></u>Â <u></u></p>
<p class="MsoNormal"><u></u>Â <u></u></p>
<p class="MsoNormal">Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if foo(["a","b","c"]):<u></u><u></u></p>
<p class="MsoNormal">Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â <wbr>Â print("Ok")<u></u><u></u></p>
<p class="MsoNormal"><u></u>Â <u></u></p>
<p class="MsoNormal"><u></u>Â <u></u></p>
<p class="MsoNormal">Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â TypeError: 'type' object is not subscriptable<u></u><u></u></p>
<p class="MsoNormal"><u></u>Â <u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal"><u></u>Â <u></u></p>
<p class="MsoNormal">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?<u></u><u></u></p>
<p class="MsoNormal"><u></u>Â <u></u></p>
<p class="MsoNormal">Is there a workaround?<u></u><u></u></p>
</div>
</div>
<br>______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/levkivskyi%40gmail.com" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>levkivskyi%40gmail.com</a><br>
<br></blockquote></div><br></div>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4