<div dir="ltr">Mypy doesn't use source code of stlib for analysis and instead uses stub files from typeshed. IIUC PyCharm can also do that (i.e. use the typeshed stubs).<div>The whole idea of typeshed is to avoid changing stlib solely for the sake of static analysis. Please open an issue on typeshed an/or PyCharm tracker.</div><div><br></div><div>--</div><div>Ivan</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 23 Apr 2019 at 20:38, Ilya Kamenshchikov <<a href="mailto:ikamenshchikov@gmail.com">ikamenshchikov@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">How would we answer the same question if it was not a part of stdlib?</div><div class="gmail_default" style="font-family:verdana,sans-serif">I am not sure it is fair to expect of Pycharm to parse / execute the __getattr__ on modules, as more elaborate implementation could even contain different types per some condition at the runtime or anything at all.</div><div class="gmail_default" style="font-family:verdana,sans-serif">The code:</div><div class="gmail_default"><pre style="font-family:Consolas;color:rgb(0,0,0);font-size:9pt">TYPE_CHECKING = <span style="color:rgb(0,0,128);font-weight:bold">False<br></span><span style="color:rgb(0,0,128);font-weight:bold">if </span>TYPE_CHECKING:<br>    <span style="color:rgb(0,0,128);font-weight:bold">from </span>.process <span style="color:rgb(0,0,128);font-weight:bold">import </span>ProcessPoolExecutor<br>    <span style="color:rgb(0,0,128);font-weight:bold">from </span>.thread <span style="color:rgb(0,0,128);font-weight:bold">import </span>ThreadPoolExecutor</pre><pre><span style="font-family:verdana,sans-serif;white-space:normal">works for type checking in PyCharm and is fast. </span></pre><pre><span style="font-family:verdana,sans-serif;white-space:normal">This is how stdlib can be an example to how side libraries can be implemented. If we can agree that this is the only clear, performant and sufficient code - then perhaps modifying mypy is a reasonable price to pay.</span></pre>Perhaps this particular case can be just patched locally by PyCharm /JetBrains, but what is a general solution to this class of problems?<br></div><div class="gmail_default"><br></div><div><div dir="ltr" class="gmail-m_6217708232712513049gmail_signature"><div dir="ltr"><div>Best Regards,<br>--<br>Ilya Kamenshchikov<br></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 23, 2019 at 7:05 PM Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">In any case I think this should be filed (by the OP) as an issue against JetBrains' PyCharm issue tracker. Who knows they may be able to special-case this in a jiffy. I don't think we should add any clever hacks to the stdlib for this.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 23, 2019 at 9:59 AM Nathaniel Smith <<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 23, 2019, 05:09 Andrew Svetlov <<a href="mailto:andrew.svetlov@gmail.com" target="_blank">andrew.svetlov@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I agree that `from typing import TYPE_CHECKING` is not desirable from<br>
the import time reduction perspective.<br>
<br>
>From my understanding code completion *can* be based on type hinting<br>
to avoid actual code execution.<br>
That's why I've mentioned that typeshed already has the correct type<br>
information.<br>
<br>
if TYPE_CHECKING:<br>
    import ...<br>
<br>
requires mypy modification.<br>
<br>
if False:<br>
    import ...<br>
<br>
Works right now for stdlib (mypy ignores stdlib code but uses typeshed<br>
anyway) but looks a little cryptic.<br>
Requires a comprehensive comment at least.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Last time I looked at this, I'm pretty sure `if False` broke at least one popular static analysis tool (ie it was clever enough to ignore everything inside `if False`) – I think either pylint or jedi?</div><div dir="auto"><br></div><div dir="auto">I'd suggest checking any clever hacks against at least: mypy, pylint/astroid, jedi, pyflakes, and pycharm. They all have their own static analysis engines, and each one has its own idiosyncratic quirks.</div><div dir="auto"><br></div><div dir="auto">We've struggled with this a *lot* in trio, and eventually ended up giving up on all forms of dynamic export cleverness; we've even banned the use of __all__ entirely. Static analysis has gotten good enough that users won't accept it not working, but it hasn't gotten good enough to handle anything but the simplest static exports in a reliable way:</div><div dir="auto">    <a href="https://github.com/python-trio/trio/pull/316" target="_blank">https://github.com/python-trio/trio/pull/316</a></div><div dir="auto">    <a href="https://github.com/python-trio/trio/issues/542" target="_blank">https://github.com/python-trio/trio/issues/542</a></div><div dir="auto"><br></div><div dir="auto">The stdlib has more leeway because when tools don't work on the stdlib then they tend to eventually add workarounds. I'm just saying, think twice before diving into clever hacks to workaround static analysis limits, and if you're going to do it then be careful to be thorough. You're basically relying on undocumented bugs, and it gets really messy really quickly.</div><div dir="auto"><br></div><div dir="auto">-n</div></div>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/mailman/options/python-dev/guido%40python.org</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail-m_6217708232712513049gmail-m_-7947721417975374521gmail_signature"><div dir="ltr"><div>--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div><div><i style="font-family:Arial,Helvetica,sans-serif;font-size:small;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);color:rgb(136,136,136)"><span>Pronouns</span>: he/him/his </i><a href="http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/" style="color:rgb(17,85,204);font-family:Arial,Helvetica,sans-serif;font-size:small;font-style:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255)" target="_blank"><i>(why is my <span>pronoun</span> here?)</i></a></div></div></div>
</blockquote></div>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/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/mailman/options/python-dev/levkivskyi%40gmail.com</a><br>
</blockquote></div>