<div dir="ltr">What if you do Union[QWidget, None] ?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 21, 2017 at 11:11 AM, J Barchan <span dir="ltr"><<a href="mailto:jnbarchan@gmail.com" target="_blank">jnbarchan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">This is my first post to this mailing list.  I am a Python(3)/PyQt/Qt newbie, so please bear with me!</div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">I use PyCharm to do my PyQt work.  The editor is very good at "highlighting dubious constructs", often relating to (what I understand to be) external "PEP" warnings.  I "annotate" my functions with the types of parameters & return values, to check for warnings and to help with code completion suggestions.</div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">I am having problems with parameters/return types which are supposed to be PyQt objects but where a valid value is <b>None</b> in Python (corresponding to 0/NULL in C++).  (This is perhaps a general Python problem maybe not specific to PyQt/Qt, I don't know, but it's a problem in the context of PyQt.)<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">Example of my own function return type:</div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default"><span style="font-family:monospace,monospace">def myfunc() -> QWidget:</span></div><div class="gmail_default"><span style="font-family:monospace,monospace">    if ...:</span></div><div class="gmail_default"><span style="font-family:monospace,monospace">        return mywidget</span></div><div class="gmail_default"><span style="font-family:monospace,monospace">    return <b>None</b></span></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">Example of calling PyQt function:</div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default"><span style="font-family:monospace,monospace">mywidget.setParent(<b>None</b>)</span></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">In both these cases PyCharm highlights the <b><span style="font-family:monospace,monospace">None</span></b> and warns me "Expected type 'QWidget', got 'None' instead".  This is to do with "type inspections".<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">(There are however <i>some</i> cases, I think, where I have looked at a PyQt function declaration stub in the <span style="font-family:monospace,monospace">.pyi</span> file which <i>seemed</i> to me to have the same signature yet it did <i>not</i> complain about <span style="font-family:monospace,monospace">None</span>, although I cannot recall which/what any difference was.)</div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">Wherever I have a Python-object type for either a parameter or a return value I expect <span style="font-family:monospace,monospace">None</span> to be acceptable.  What is going on here, what do I have to do to my PyCharm/PyQt code acceptable without this warning (and, no, I don't want to turn all "type inspection" warnings off)?</div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">Many thanks in advance if I get an answer!</div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br clear="all"></div></div>
<br>______________________________<wbr>_________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.<wbr>riverbankcomputing.com/<wbr>mailman/listinfo/pyqt</a><br></blockquote></div><br></div>