[PyQt] PyQt/PyCharm/PEP problem with PyQt types
jnbarchan at gmail.com
Tue Nov 21 16:11:44 GMT 2017
This is my first post to this mailing list. I am a Python(3)/PyQt/Qt
newbie, so please bear with me!
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
I am having problems with parameters/return types which are supposed to be
PyQt objects but where a valid value is *None* 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
Example of my own function return type:
def myfunc() -> QWidget:
Example of calling PyQt function:
In both these cases PyCharm highlights the *None* and warns me "Expected
type 'QWidget', got 'None' instead". This is to do with "type inspections".
(There are however *some* cases, I think, where I have looked at a PyQt
function declaration stub in the .pyi file which *seemed* to me to have the
same signature yet it did *not* complain about None, although I cannot
recall which/what any difference was.)
Wherever I have a Python-object type for either a parameter or a return
value I expect None 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)?
Many thanks in advance if I get an answer!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt