Skip to content

Commit

Permalink
fix(brain_qt): fix signal has no connect member
Browse files Browse the repository at this point in the history
`pylint` detects `Qt` signals as `FunctionDef`s instead of
`ClassDef`s, so they are not properly detected in PySide2 5.15.2+ and
PySide6. The patch from PR pylint-dev#900 is used to fix this.

Fixes PyCQA/pylint #4040 and PyCQA/pylint #5378
  • Loading branch information
adamgranthendry committed Jun 24, 2022
1 parent 1fde25b commit 060b4b2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions astroid/brain/brain_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ def emit(self, signal): pass
)


def _looks_like_pyside2_or_6_signal(node):
"""Detect a PySide2 or PySide6 signal. These changed locations as of QT 5ish apparently."""

is_pyside_node = node.qname().partition(".")[0] in {"PySide2", "PySide6"}
is_named_signal = any(
cls.qname() == "Signal" for cls in node.instance_attrs.get("__class__", [])
)

return is_pyside_node and is_named_signal


register_module_extender(AstroidManager(), "PyQt4.QtCore", pyqt4_qtcore_transform)
AstroidManager().register_transform(
nodes.FunctionDef, transform_pyqt_signal, _looks_like_signal
Expand All @@ -80,3 +91,6 @@ def emit(self, signal): pass
transform_pyside_signal,
lambda node: node.qname() in {"PySide.QtCore.Signal", "PySide2.QtCore.Signal"},
)
AstroidManager().register_transform(
nodes.FunctionDef, transform_pyqt_signal, _looks_like_pyside2_or_6_signal
)

0 comments on commit 060b4b2

Please sign in to comment.