blob: 9f778355fb7edfee6c7a0c6e443214215eda26de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
from importlib.util import find_spec
import pytest
from astroid import Uninferable, 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="These tests require the PyQt6 library.")
class TestBrainQt:
AstroidManager.brain["extension_package_whitelist"] = {"PyQt6"}
@staticmethod
def test_value_of_lambda_instance_attrs_is_list():
"""Regression test for https://github.com/pylint-dev/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 #@
"""
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, UnboundMethod)
# scoped_nodes.Lambda.instance_attrs is typed as Dict[str, List[NodeNG]]
assert isinstance(attribute_node.instance_attrs["connect"][0], FunctionDef)
@staticmethod
def test_implicit_parameters() -> None:
"""Regression test for https://github.com/pylint-dev/pylint/issues/6464."""
src = """
from PyQt6.QtCore import QTimer
timer = QTimer()
timer.timeout.connect #@
"""
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.implicit_parameters() == 1
@staticmethod
def test_slot_disconnect_no_args() -> None:
"""Test calling .disconnect() on a signal.
See https://github.com/pylint-dev/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
|