Skip to content

qt brain: Make slot argument optional for disconnect() #1550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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?
=============================
Expand Down
4 changes: 3 additions & 1 deletion astroid/brain/brain_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/unittest_brain_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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