Closed edreamleo closed 2 years ago
Possibly a windows only issue, the example does not crash for me. What is the commit used in your local pylint ?
@Pierre-Sassoulas
ba08c9d1ab8b624b4491a29bfc2f274dc00eeab8
Author: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> 2022-04-06 14:43:11
Committer: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> 2022-04-06 16:19:42
Parent: e7be960c810e9333064d4ea09a5cda43d77c0ec7 (Add ``_option_dicts`` attribute to ``_ArgumentsManager``)
Branches: main, remotes/origin/main
Follows: v2.13.5
Precedes:
Move ``test_generate_config_disable_symbolic_names``
@edreamleo Could I ask you to print out attr_nodes
on L1055?
L1057 was changed in https://github.com/PyCQA/pylint/pull/5544. It might be possible that this caused a regression? But honestly I don't immediately see how attr_nodes = owner.getattr(node.attrname)
can return a list of strings... Peculiar bug 😅
@DanielNoord What do you mean "on L1055"?
@DanielNoord What do you mean "on L1055"?
Oh sorry, should have been clearer. Line 1055 in c:\leo.repo\ekr-pylint\pylint\checkers\typecheck.py
. The crash occurs on line 1057 and it might help us to know what attr_nodes
is on line 1055 just before the crash.
@DanielNoord Will do. Probably later today.
@DanielNoord
At line 1057 I replaced the unguarded access to attr_parent = attr_node.parent
with:
try:
attr_parent = attr_node.parent
except AttributeError:
print('EKR', attr_node) ###
raise
The extra output was: EKR self
.
BTW, for reasons that I do not understand, adding just the print statement (outside the try/except) hung pylint.
@DanielNoord Sorry, wrong recipient the first time.
On second thought, the "hang" is likely a Leo artifact. A pipe created by subprocess.Popen probably blocked. It's an ongoing Leo issue :-)
I'm going to ping @jacobtylerwalls as this is probably related to his PR #5544.
@edreamleo Do you have a short code snippet that always trigger this crash?
@DanielNoord No, but I should be able to create one. One of the failing files is fairly short.
@DanielNoord Here is a reduction of leo/core/leoPrinting.py that still crashes for me:
"""
Test file for pylint issue #6221: https://github.com/PyCQA/pylint/issues/6221
Adapted from leo/core/leoPrinting.py
"""
try: # #1973
from leo.core.leoQt import printsupport, QtGui
from leo.core.leoQt import DialogCode
except Exception:
printsupport = QtGui = None # type:ignore
DialogCode = None # type:ignore
class PrintingController:
"""A class supporting the commands in Leo's File:Print menu."""
document = None # #6221: Suppress extraneous pylint complaint.
c = None # #6221: Suppress extraneous pylint complaint.
def preview_body(self, event=None):
"""Preview the body of the selected node."""
doc = self.document(self.c.p.b)
self.preview_doc(doc)
def preview_doc(self, doc):
"""Preview the document."""
# pylint: disable=no-member
dialog = printsupport.QPrintPreviewDialog()
dialog.setSizeGripEnabled(True)
dialog.paintRequested.connect(doc.print) # <=== OOPS!
dialog.exec_()
@DanielNoord Here is a reduction of leo/core/leoPrinting.py that still crashes for me:
""" Test file for pylint issue #6221: https://github.com/PyCQA/pylint/issues/6221 Adapted from leo/core/leoPrinting.py """ from leo.core import leoGlobals as g # # Qt imports. May fail from the bridge. try: # #1973 from leo.core.leoQt import printsupport, QtGui from leo.core.leoQt import DialogCode except Exception: printsupport = QtGui = None # type:ignore DialogCode = None # type:ignore class PrintingController: """A class supporting the commands in Leo's File:Print menu.""" document = None c = None def preview_body(self, event=None): """Preview the body of the selected node.""" doc = self.document(self.c.p.b) self.preview_doc(doc) def preview_doc(self, doc): """Preview the document.""" # pylint: disable=no-member dialog = printsupport.QPrintPreviewDialog() dialog.setSizeGripEnabled(True) dialog.paintRequested.connect(doc.print) dialog.exec_()
Hmm, I can't get that to crash on main
on Mac. One thing I notice is that those imports are not used in the code. Are they necessary for pylint
to crash?
Might need to spin up a fresh venv with the packages from the report. That can affect inference.
@DanielNoord Yes, the imports appear necessary. I admit, this particular snippet is very strange. If you like, I can try to find another snippet.
Let's just continue bisecting this one. Can you include the entire crash output? My guess is that chained assignment to printsupport
in the except is one-half of what's needed, given where the disable no-member is located.
Might need to spin up a fresh venv with the packages from the report. That can affect inference.
I did a fresh venv with pip install leo
, but I might obviously be missing an important package.
@DanielNoord I may be able to simplify the example...
@DanielNoord On my system all the imports succeed, so the example can just start with the following:
from leo.core.leoQt import printsupport, QtGui
from leo.core.leoQt import DialogCode
This still gives a fatal error, as expected.
But: we should be able to simplify the example further by using PyQt6 imports defined in leoQt.py (via leoQt6.py):
from PyQt6 import QtWidgets
from PyQt6 import QtPrintSupport as printsupport
DialogCode = QtWidgets.QDialog.DialogCode
But now pylint doesn't crash, and instead complains:
c:\test\test_leoPrinting.py:34:14: E1102: self.document is not callable.
@DanielNoord Hmm. leoQt.py gets access to the symbols in leoQt6.py this way:
from leo.core.leoQt6 import *
So maybe this extra level of indirection is bothering pylint.
@edreamleo could you post the entire crash report? You can wrap it in a <details>
tag so that it doesn't overwhelm the thread.
@jacobtylerwalls Will do.
@jacobtylerwalls Here is the entire crash report, from pylint-crash-2022-04-08-05.txt:
And here is the console output, with an extra trace inserted in typecheck.py:
C:\leo.repo\leo-editor>python -m pylint-leo -f c:\test\test_leoPrinting.py
************* Module Test.test_leoPrinting
c:\test\test_leoPrinting.py:34:14: E1102: self.document is not callable (not-callable)
EKR self # <==== new trace.
Exception on node <Attribute.connect l.42 at 0x1b88e392050> in file 'c:\test\test_leoPrinting.py'
Traceback (most recent call last):
File "c:\leo.repo\ekr-pylint\pylint\utils\ast_walker.py", line 73, in walk
callback(astroid)
File "c:\leo.repo\ekr-pylint\pylint\checkers\typecheck.py", line 1058, in visit_attribute
attr_parent = attr_node.parent
AttributeError: 'str' object has no attribute 'parent'
c:\test\test_leoPrinting.py:1:0: F0001: Fatal error while checking 'c:\test\test_leoPrinting.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in 'C:\Users\Edward Ream\AppData\Local\pylint\pylint\Cache\pylint-crash-2022-04-08-05.txt'. (fatal)
.1 file, time: 0.72 sec.
C:\leo.repo\leo-editor>
Thanks, I can reproduce it now. I needed to:
PyQt6
into a venv as wellleo-editor
so that I had the local project file leo.core.leoQt
python3.8 -m pylint <crasher-path> --ignore-on-opaque-inference=no --extension-pkg-allow-list=PyQt6.QtPrintSupport --unsafe-load-any-extension=yes
Assigning myself with the intent of having a look soon at the root cause, but any help is welcome. Thanks for the report!
Bisected it to #5544 in 2.14 (glad we didn't rush it into 2.13!) I just need to restore an except
for ast's built from living objects. Thanks for testing on main
!
@jacobtylerwalls You're welcome. Glad to hear the fix was straightforward.
@jacobtylerwalls The code in ee94d81 works for me. Many thanks for the quick fix.
@edreamleo actually, may I ask you to test an alternative solution? This is the root cause and actually testable in a real way! https://github.com/PyCQA/astroid/pull/1505
@jacobtylerwalls Will do. Probably tomorrow.
Tests still fail for me, but I suspect that I have not installed the PR properly. Here is what I did:
git checkout .
Now python -m pylint-leo -v
reports:
pylint 2.14.0-dev0
astroid 2.12.0-dev0
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)]
What should I do now? Thanks.
Hmm. I suppose I should do gh pr checkout 1505
, but I'm not sure what that means.
Ok, from https://github.com/cli/cli I did: git clone https://github.com/cli/cli
I'll get the gh command working and see if that helps :-)
I think you need to switch the branch to the qt-brain
one from @jacobtylerwalls as the default one is main, so between
git switch qt-brain
@Pierre-Sassoulas Thanks. I'll try that.
Also, I see that there is an msi installer for gh cli on Windows, which I've just installed. Now 'gh' works.
@Pierre-Sassoulas git switch qt-brain
appears to have worked.
I'm still running tests (they take over 1000 sec), but there are no crashes in the files that crashed before, only new pylint warnings :-)
pip install .
issued warnings, but apparently I can ignore them. Here is the full log:
@Pierre-Sassoulas All tests just completed: 282 files, time: 1198.07 sec.
So I have done all the testing that I can. Thanks again for the quick fix.
Reopening to make sure we release astroid
and depend on it in pylint
for 2.14.
Fixed in #6398
Bug description
Note: Crash appeared several times in different files. Including all of pylint-crash-2022-04-07-07.txt made the body text of this issue too big.
pylint crashed with a
AttributeError
and with the following stacktrace:Note Several more similar crashes appear in the crash report.
Configuration
No response
Command used
Pylint output
Expected behavior
No pylint crashes :-) The pylint messages appear reasonable.
Pylint version
OS / Environment
Leo 6.6.1-devel, ekr-unit-tests branch, build 77f47d62b3 2022-04-06 13:50:52 -0500 Python 3.10.4, PyQt version 6.2.4 Windows 10 AMD64 (build 10.0.22000) SP0
Additional dependencies
C:\leo.repo\leo-editor>python -m pip freeze
astroid==2.11.2 atomicwrites==1.4.0 attrs==21.4.0 beautifulsoup4==4.10.0 black==22.3.0 bleach==4.1.0 certifi==2021.10.8 charset-normalizer==2.0.12 click==8.1.0 colorama==0.4.4 coverage==6.3.2 cycler==0.11.0 defusedxml==0.7.1 dialite==0.5.3 dill==0.3.4 distlib==0.3.4 docutils==0.18.1 entrypoints==0.4 feedparser==6.0.8 filelock==3.6.0 flexx==0.8.3 fonttools==4.31.2 idna==3.3 ImageHash==4.2.1 iniconfig==1.1.1 isort==5.10.1 Jinja2==3.1.1 jsonschema==4.4.0 jupyter-client==7.2.1 jupyter-core==4.9.2 jupyterlab-pygments==0.1.2 kiwisolver==1.4.1 lazy-object-proxy==1.7.1 leo==6.6 lxml==4.8.0 Markdown==3.3.6 MarkupSafe==2.1.1 matplotlib==3.5.1 mccabe==0.7.0 mistune==0.8.4 mypy-extensions==0.4.3 nbclient==0.5.13 nbconvert==6.4.5 nbformat==5.2.0 nest-asyncio==1.5.5 numpy==1.22.3 packaging==21.3 pandocfilters==1.5.0 pathspec==0.9.0 Pillow==9.0.1 platformdirs==2.5.1 pluggy==1.0.0 pscript==0.7.7 py==1.11.0 pyenchant==3.2.2 Pygments==2.11.2 -e git+https://github.com/PyCQA/pylint.git@ba08c9d1ab8b624b4491a29bfc2f274dc00eeab8#egg=pylint pyparsing==3.0.7 PyQt5==5.15.6 PyQt5-Qt5==5.15.2 PyQt5-sip==12.9.1 PyQt6==6.2.3 PyQt6-Qt6==6.2.4 PyQt6-sip==13.2.1 PyQt6-WebEngine==6.2.1 PyQt6-WebEngine-Qt6==6.2.4 pyrsistent==0.18.1 pytest==7.1.1 pytest-cov==3.0.0 python-dateutil==2.8.2 PyWavelets==1.3.0 pywin32==303 PyYAML==6.0 pyzmq==22.3.0 requests==2.27.1 scipy==1.8.0 Send2Trash==1.8.0 sgmllib3k==1.0.0 six==1.16.0 soupsieve==2.3.1 testpath==0.6.0 toml==0.10.2 tomli==2.0.1 tornado==6.1 tox==3.24.5 traitlets==5.1.1 types-docutils==0.18.0 types-requests==2.27.15 types-urllib3==1.26.11 typing_extensions==4.1.1 urllib3==1.26.9 virtualenv==20.14.0 webencodings==0.5.1 webruntime==0.5.8 websockets==10.2 windows-curses==2.3.0 wrapt==1.14.0