PyCharm 显示 PyQt 方法的错误参数信息 [英] PyCharm showing wrong parameter info for PyQt methods

查看:56
本文介绍了PyCharm 显示 PyQt 方法的错误参数信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 GUI 方面没有做很多工作,但我决定从偶尔使用 PyQt4 转向 PyQt5.我的 IDE 给了我一些关于 __init__ 函数的警告,特别是 QWidget 和 QMainWindow.

I don't do a lot of work in GUI's, but I've decided to move from occasionally using PyQt4 to PyQt5. My IDE is giving me warnings about some of the __init__ functions, particularly QWidget and QMainWindow.

如果您查看 IntelliSense 的参数,您会看到 parent 参数具有默认值,而 flags 没有.IDE 告诉我 flags 未填充,但是当我不提供它时,什么也没有发生.为什么会发生这种情况?

If you look at the IntelliSense'd parameters, you'll see that the parentparameter has a default and the flags does not. The IDE tells me that flags is unfilled, but when I don't provide it, nothing happens. Why is this happening?

我使用的是 Python 3.5.

I'm using Python 3.5.

推荐答案

正确的签名是这样的:

QMainWindow(parent: QWidget = None,
            flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags())

所以看起来你的 IDE 中的 IntelliSense 要么不知道如何正确解析类型提示,要么 必要的存根文件 未安装.只有两个参数:parentflags,两者都有默认值.

So it looks like the IntelliSense in your IDE either does not know how to parse type-hints properly, or the necessary stub files aren't installed. There are only two arguments: parent and flags, both of which have defaults.

(注意:永远不要将 self.__class__super 一起使用,因为在某些情况下它会导致无限递归.始终将子类作为第一个参数传入- 除非您使用的是 Python 3,在这种情况下,您可以省略所有参数).

(NB: you should never use self.__class__ with super as it can lead to an infinite recursion under certain circumstances. Always pass in the subclass as the first argument - unless you're using Python 3, in which case you can omit all the arguments).

这篇关于PyCharm 显示 PyQt 方法的错误参数信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆