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 crash in no-member check for C extensions #6235

Closed

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Apr 8, 2022

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Closes #6221. Regression in 129c730 (unreleased 2.14)

  • Add test

@jacobtylerwalls jacobtylerwalls added this to the 2.14.0 milestone Apr 8, 2022
@coveralls
Copy link

coveralls commented Apr 8, 2022

Pull Request Test Coverage Report for Build 2117322267

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.0004%) to 93.896%

Totals Coverage Status
Change from base Build 2113760049: 0.0004%
Covered Lines: 15889
Relevant Lines: 16922

πŸ’› - Coveralls

@jacobtylerwalls jacobtylerwalls changed the title Fix crash in c-extension-no-member check Fix crash in no-member check for C extensions Apr 8, 2022
ChangeLog Outdated Show resolved Hide resolved
@Pierre-Sassoulas Pierre-Sassoulas added the Crash πŸ’₯ A bug that makes pylint crash label Apr 8, 2022
jacobtylerwalls and others added 2 commits April 8, 2022 11:47
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
@jacobtylerwalls
Copy link
Member Author

I spent a cycle trying to figure out how to test this. We would need a package with a C extension without ballooning our test dependencies. coverage is the package used for that already, but then we need an involved solution to reproduce the inference ambiguity on some element in coverage, possibly through inducing an import name collision via another locally installed package (see report, with leo.core.Qt6 importing names from Qt6 that might differ from the c extension Qt6. It's a bit overwhelming.

@jacobtylerwalls jacobtylerwalls marked this pull request as ready for review April 8, 2022 17:10
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a suggestion, we could also post the URL to this comment. I think adding the pragma no cover is important if we're voluntarily not testing the code.

pylint/checkers/typecheck.py Outdated Show resolved Hide resolved
@jacobtylerwalls
Copy link
Member Author

For future reference, here is a test case for pylint that fails if PyQt6 is installed.

diff --git a/requirements_test.txt b/requirements_test.txt
index 2e35f584..04aac371 100644
--- a/requirements_test.txt
+++ b/requirements_test.txt
@@ -6,6 +6,7 @@ pre-commit~=2.17;python_full_version>="3.6.2"
 tbump~=6.6.0
 contributors-txt>=0.7.3
 pyenchant~=3.2
+PyQt6~=6.2
 pytest-cov~=3.0
 pytest-profiling~=1.7
 pytest-xdist~=2.5
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/functional/n/no/no_member_c_extension.py b/tests/functional/n/no/no_member_c_extension.py
new file mode 100644
index 00000000..e09f7d03
--- /dev/null
+++ b/tests/functional/n/no/no_member_c_extension.py
@@ -0,0 +1,9 @@
+"""Regression test for https://github.com/PyCQA/pylint/issues/6221"""
+
+# local import that creates ambiguity with test requirement PyQt6
+# PyQt6 has the name printsupport
+from tests.input.qt6 import printsupport
+
+dialog = printsupport.QPrintPreviewDialog
+# paintRequested (nodes.FunctionDef) is the owner of the name connect, not the module
+dialog.paintRequested.connect()
diff --git a/tests/functional/n/no/no_member_c_extension.rc b/tests/functional/n/no/no_member_c_extension.rc
new file mode 100644
index 00000000..b3320786
--- /dev/null
+++ b/tests/functional/n/no/no_member_c_extension.rc
@@ -0,0 +1,2 @@
+[MASTER]
+extension-pkg-allow-list=PyQt6.QtPrintSupport
diff --git a/tests/input/qt6.py b/tests/input/qt6.py
new file mode 100644
index 00000000..44312ea8
--- /dev/null
+++ b/tests/input/qt6.py
@@ -0,0 +1 @@
+from PyQt6 import QtPrintSupport as printsupport

@jacobtylerwalls jacobtylerwalls marked this pull request as draft April 8, 2022 22:44
@jacobtylerwalls
Copy link
Member Author

Hold up, there's a deeper root cause that's fixable in the astroid brain for qt.

@jacobtylerwalls
Copy link
Member Author

Superseded by pylint-dev/astroid#1505

@jacobtylerwalls jacobtylerwalls deleted the living-objects branch April 8, 2022 23:57
@jacobtylerwalls jacobtylerwalls removed this from the 2.14.0 milestone Apr 8, 2022
@Pierre-Sassoulas
Copy link
Member

But isn't it a good thing that we do not crash in case there's an issue in a brain or in astroid's analysis ?

@jacobtylerwalls
Copy link
Member Author

I guess my thought was that we don't want to silence programming errors. Someone could contribute a broken brain and not realize it if we're just catching errors in pylint.

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Apr 9, 2022

I agree we should not silence our own errors. But on the other hand, the brain was contributed with an error and we have a really hard time reproducing the bug, even adding an automated test to check the fix we added is complicated. What could make sure that we do not contribute faulty brains in the future ? (Maybe better typing in astroid? A lot was already done for typing but it's not possible to activate mypy at this point in time)

@jacobtylerwalls
Copy link
Member Author

Maybe better typing in astroid?

I hear that astroid is not ready for comprehensive type-checking. Maybe we can start turning it on file by file, or just in the brains and work our way toward the center. That's what I'm doing in another library I work on (start on edges).

I added some typing to the astroid PR that will raise mypy errors without the fix.

@Pierre-Sassoulas
Copy link
Member

I hear that astroid is not ready for comprehensive type-checking.

It's closer and closer though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash πŸ’₯ A bug that makes pylint crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'str' object has no attribute 'parent'
3 participants