Skip to content
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

Fix instance_attrs building error in Qt brain #1505

Merged
merged 8 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ What's New in astroid 2.11.3?
=============================
Release date: TBA

* Fixed an error in the Qt brain when building ``instance_attrs``.

Closes PyCQA/pylint#6221
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved


What's New in astroid 2.11.2?
Expand Down
12 changes: 6 additions & 6 deletions astroid/brain/brain_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def emit(self, *args):
"""
)
signal_cls = module["pyqtSignal"]
node.instance_attrs["emit"] = signal_cls["emit"]
node.instance_attrs["disconnect"] = signal_cls["disconnect"]
node.instance_attrs["connect"] = signal_cls["connect"]
node.instance_attrs["emit"] = [signal_cls["emit"]]
node.instance_attrs["disconnect"] = [signal_cls["disconnect"]]
node.instance_attrs["connect"] = [signal_cls["connect"]]


def transform_pyside_signal(node):
Expand All @@ -52,9 +52,9 @@ def emit(self, *args):
"""
)
signal_cls = module["NotPySideSignal"]
node.instance_attrs["connect"] = signal_cls["connect"]
node.instance_attrs["disconnect"] = signal_cls["disconnect"]
node.instance_attrs["emit"] = signal_cls["emit"]
node.instance_attrs["connect"] = [signal_cls["connect"]]
node.instance_attrs["disconnect"] = [signal_cls["disconnect"]]
node.instance_attrs["emit"] = [signal_cls["emit"]]


def pyqt4_qtcore_transform():
Expand Down
1 change: 1 addition & 0 deletions requirements_test_brain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ types-attrs
nose
numpy>=1.17.0
python-dateutil
PyQt6
types-python-dateutil
six
types-six
36 changes: 36 additions & 0 deletions tests/unittest_brain_qt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt

from importlib.util import find_spec

import pytest

from astroid import extract_node
from astroid.bases import UnboundMethod
from astroid.manager import AstroidManager
from astroid.nodes import FunctionDef

HAS_PYQT6 = find_spec("PyQt6")


@pytest.mark.skipif(HAS_PYQT6 is None, reason="This test requires the PyQt6 library.")
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved
class TestBrainQt:
@staticmethod
def test_value_of_lambda_instance_attrs_is_list():
"""Regression test for https://github.com/PyCQA/pylint/issues/6221

A crash occurred in pylint when a nodes.FunctionDef was iterated directly,
giving items like "self" instead of iterating a one-element list containing
the wanted nodes.FunctionDef.
"""
src = """
from PyQt6 import QtPrintSupport as printsupport
printsupport.QPrintPreviewDialog.paintRequested #@
"""
AstroidManager.brain["extension_package_whitelist"] = {"PyQt6.QtPrintSupport"}
node = extract_node(src)
attribute_node = node.inferred()[0]
# scoped_nodes.Lambda.instance_attrs is typed as Dict[str, List[NodeNG]]
assert isinstance(attribute_node, UnboundMethod)
assert isinstance(attribute_node.instance_attrs["connect"][0], FunctionDef)