Skip to content

Commit a62e7cf

Browse files
adam-grant-hendryadamgranthendryDanielNoord
authored
Fix the qt brain for Signals on PySide 2 and 6 (#1654)
Co-authored-by: Hendry, Adam <adam.hendry@medtronic.com> Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
1 parent 90362ad commit a62e7cf

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ astroid.egg-info/
1515
.pytest_cache/
1616
.mypy_cache/
1717
venv
18+
doc/_build/

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ What's New in astroid 2.12.0?
66
=============================
77
Release date: TBA
88

9+
* Fix signal has no ``connect`` member for PySide2 5.15.2+ and PySide6
10+
11+
Closes #4040, #5378
12+
913
* ``astroid`` now requires Python 3.7.2 to run.
1014

1115
* Avoid setting a Call as a base for classes created using ``six.with_metaclass()``.

astroid/brain/brain_qt.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010
from astroid.manager import AstroidManager
1111

1212

13-
def _looks_like_signal(node, signal_name="pyqtSignal"):
14-
if "__class__" in node.instance_attrs:
13+
def _looks_like_signal(
14+
node: nodes.FunctionDef, signal_name: str = "pyqtSignal"
15+
) -> bool:
16+
"""Detect a Signal node."""
17+
klasses = node.instance_attrs.get("__class__", [])
18+
# On PySide2 or PySide6 (since Qt 5.15.2) the Signal class changed locations
19+
if node.qname().partition(".")[0] in {"PySide2", "PySide6"}:
20+
return any(cls.qname() == "Signal" for cls in klasses) # pragma: no cover
21+
if klasses:
1522
try:
16-
cls = node.instance_attrs["__class__"][0]
17-
return cls.name == signal_name
18-
except AttributeError:
23+
return klasses[0].name == signal_name
24+
except AttributeError: # pragma: no cover
1925
# return False if the cls does not have a name attribute
2026
pass
2127
return False

script/.contributors_aliases.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,9 @@
169169
"ville.skytta@iki.fi": {
170170
"mails": ["ville.skytta@iki.fi", "ville.skytta@upcloud.com"],
171171
"name": "Ville Skyttä"
172+
},
173+
"adam.grant.hendry@gmail.com": {
174+
"mails": ["adam.grant.hendry@gmail.com"],
175+
"name": "Adam Hendry"
172176
}
173177
}

tests/unittest_brain_qt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
HAS_PYQT6 = find_spec("PyQt6")
1515

1616

17-
@pytest.mark.skipif(HAS_PYQT6 is None, reason="This test requires the PyQt6 library.")
17+
@pytest.mark.skipif(HAS_PYQT6 is None, reason="These tests require the PyQt6 library.")
1818
class TestBrainQt:
1919
AstroidManager.brain["extension_package_whitelist"] = {"PyQt6"}
2020

0 commit comments

Comments
 (0)