diff --git a/ChangeLog b/ChangeLog index b322afd185..e1a27561eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,8 @@ What's New in astroid 2.11.6? ============================= Release date: TBA +* The Qt brain now correctly treats calling ``.disconnect()`` (with no + arguments) on a slot as valid. What's New in astroid 2.11.5? diff --git a/astroid/brain/brain_qt.py b/astroid/brain/brain_qt.py index c02508478f..6b97bf671a 100644 --- a/astroid/brain/brain_qt.py +++ b/astroid/brain/brain_qt.py @@ -24,10 +24,12 @@ def _looks_like_signal(node, signal_name="pyqtSignal"): def transform_pyqt_signal(node: nodes.FunctionDef) -> None: module = parse( """ + _UNSET = object() + class pyqtSignal(object): def connect(self, slot, type=None, no_receiver_check=False): pass - def disconnect(self, slot): + def disconnect(self, slot=_UNSET): pass def emit(self, *args): pass diff --git a/tests/unittest_brain_qt.py b/tests/unittest_brain_qt.py index f9805bce77..93ef4dd110 100644 --- a/tests/unittest_brain_qt.py +++ b/tests/unittest_brain_qt.py @@ -52,3 +52,21 @@ def test_implicit_parameters() -> None: pytest.skip("PyQt6 C bindings may not be installed?") assert isinstance(attribute_node, FunctionDef) assert attribute_node.implicit_parameters() == 1 + + @staticmethod + def test_slot_disconnect_no_args() -> None: + """Test calling .disconnect() on a signal. + + See https://github.com/PyCQA/astroid/pull/1531#issuecomment-1111963792 + """ + src = """ + from PyQt6.QtCore import QTimer + timer = QTimer() + timer.timeout.disconnect #@ + """ + node = extract_node(src) + attribute_node = node.inferred()[0] + if attribute_node is Uninferable: + pytest.skip("PyQt6 C bindings may not be installed?") + assert isinstance(attribute_node, FunctionDef) + assert attribute_node.args.defaults