Open jyc001 opened 3 years ago
What do you mean with "XXX.clickked.XXX 's autocompletion"? Can you maybe show a screenshot or code sample?
Here's the diff for reference. https://github.com/python-qt-tools/pyqt5-stubs/compare/5.14.2.2...5.15.2.0 It certainly became more complex, but also more accurate to the real stuff. Anyways, yeah, it would be helpful to see a minimal example of code showing the issue and a screenshot of the issue.
old...
# Support for new-style signals and slots.
class pyqtSignal: # add methods
def __init__(self, *types: typing.Any, name: str = ...) -> None: ...
def emit(self, *args: typing.Any) -> None: ...
def connect(self, slot: "PYQT_SLOT") -> None: ...
def disconnect(self, slot: "PYQT_SLOT"=None) -> None: ...
class pyqtBoundSignal:
def emit(self, *args: typing.Any) -> None: ...
# Convenient type aliases.
PYQT_SIGNAL = typing.Union[pyqtSignal, pyqtBoundSignal]
PYQT_SLOT = typing.Union[typing.Callable[..., None], pyqtBoundSignal]
and new.
class pyqtBoundSignal:
signal = ... # type: str
def __getitem__(self, key: object) -> "pyqtBoundSignal": ...
def emit(self, *args: typing.Any) -> None: ...
def connect(self, slot: "PYQT_SLOT") -> "QMetaObject.Connection": ...
@typing.overload
def disconnect(self) -> None: ...
@typing.overload
def disconnect(self, slot: typing.Union["PYQT_SLOT", "QMetaObject.Connection"]) -> None: ...
class pyqtSignal:
signatures = ... # type: typing.Tuple[str, ...]
def __init__(self, *types: typing.Any, name: str = ...) -> None: ...
@typing.overload
def __get__(self, instance: None, owner: typing.Type["QObject"]) -> "pyqtSignal": ...
@typing.overload
def __get__(self, instance: "QObject", owner: typing.Type["QObject"]) -> pyqtBoundSignal: ...
# Convenient type aliases.
PYQT_SLOT = typing.Union[typing.Callable[..., object], pyqtBoundSignal]
QObjectT = typing.TypeVar("QObjectT", bound="QObject")
self.pushbutton.clicked.connect() 's clicked.connect()
just like self.pushbutton.clicked.connect()
Trying with 5.15.3.0.
But...
When I ctrl
+left mouse
PyCharm takes me to _their_ stubs. Though, the same goes for 5.14.2.2 for me here, so maybe I just have something wrong. I'll see if I can figure out how to disable the builtins, or...
If I rename PyCharm's builtin stubs to avoid their usage (is there a better way?) then I see the issue in pyqt5-stubs==5.15.2
while it works in pyqt5-stubs==5.14.2.2
. In all cases it is offering the popup to complete .pushbutton
and .clicked
, but doesn't manage to understand how to work with .clicked
. But, it does understand how to handle .s
and .s.connect
...
Ok, I added a few more things and still have no theories. Everything I code gets completion hints for connect
. The button doesn't.
import typing
from PyQt5 import QtCore
from PyQt5 import QtWidgets
class C(QtCore.QObject):
b: QtCore.pyqtSignal = QtCore.pyqtSignal()
c: typing.ClassVar[QtCore.pyqtSignal] = QtCore.pyqtSignal()
pushbutton: QtWidgets.QPushButton
def __init__(self, parent=None):
super().__init__(parent)
self.pushbutton = QtWidgets.QPushButton()
def m(self):
self.b.connect()
self.c.connect()
self.pushbutton.clicked.con
class I(C):
pass
class D(QtCore.QObject):
c: C
i: I
def __init__(self, parent=None):
super().__init__(parent)
self.c = C()
self.i = I()
def m(self):
self.c.b.connect()
self.c.c.connect()
self.i.b.connect()
self.i.c.connect()
self.c.pushbutton.clicked.conn
self.i.pushbutton.clicked.conn
# what ctrl+left-click goes to for `.clicked
#
# class QAbstractButton(QWidget):
# <snip>
# clicked: typing.ClassVar[QtCore.pyqtSignal]
after I upgrade to pyqt5-stubs version 5.15.2.0, the XXX.clickked.XXX 's autocompletion in pycharm(2021.1) didn"t work.But in Vscode(with pylance) it works well.Then i downgrade to pyqt5-stubds version 5.14.2.2 ,the XXX.clickked.XXX 's autocompletion in pycharm(2021.1) starts working.