pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.25k stars 1.12k forks source link

Crash ``'Module' object has no attribute 'doc_node'`` (VSCode PyLint Extension >= v2022.1.10911002) #6505

Closed timeterror closed 2 years ago

timeterror commented 2 years ago

Bug description

Issue was bumped from https://github.com/microsoft/vscode-pylint/issues/77.

"An example that crashes."
# Local modules
import logging

pylint crashed with an AttributeError and with the following stacktrace:

Traceback (most recent call last):
  File "c:\Users\marc.pont\.vscode\extensions\ms-python.pylint-2022.1.10911002\bundled\libs\pylint\lint\pylinter.py", line 1111, in _check_files
    self._check_file(get_ast, check_astroid_module, file)
  File "c:\Users\marc.pont\.vscode\extensions\ms-python.pylint-2022.1.10911002\bundled\libs\pylint\lint\pylinter.py", line 1146, in _check_file
    check_astroid_module(ast_node)
  File "c:\Users\marc.pont\.vscode\extensions\ms-python.pylint-2022.1.10911002\bundled\libs\pylint\lint\pylinter.py", line 1298, in check_astroid_module
    retval = self._check_astroid_module(
  File "c:\Users\marc.pont\.vscode\extensions\ms-python.pylint-2022.1.10911002\bundled\libs\pylint\lint\pylinter.py", line 1345, in _check_astroid_module
    walker.walk(node)
  File "c:\Users\marc.pont\.vscode\extensions\ms-python.pylint-2022.1.10911002\bundled\libs\pylint\utils\ast_walker.py", line 73, in walk
    callback(astroid)
  File "c:\Users\marc.pont\.vscode\extensions\ms-python.pylint-2022.1.10911002\bundled\libs\pylint\checkers\base\docstring_checker.py", line 109, in visit_module
    self._check_docstring("module", node)
  File "c:\Users\marc.pont\.vscode\extensions\ms-python.pylint-2022.1.10911002\bundled\libs\pylint\checkers\base\docstring_checker.py", line 161, in _check_docstring
    docstring = node.doc_node.value if node.doc_node else None
AttributeError: 'Module' object has no attribute 'doc_node'

Configuration

The extension settings are:

"pylint.args": [
        "--max-line-length=100",
        "--disable=C0413,W0105,W0511,W1201,W1202,W1203",
        "--extension-pkg-whitelist=pyodbc,pandas,numpy",
        "--ignored-classes=DatetimeIndex,ExtensionIndex,Index",
        "--good-names=Run,_",
        "--max-args=25",
        "--argument-rgx=\\b[a-zA-Z_][a-zA-Z0-9_]{0,30}",
        "--attr-rgx=\\b[a-zA-Z_][a-zA-Z0-9_]{0,30}",
        "--class-rgx=\\b[a-zA-Z_][a-zA-Z0-9_]{0,30}",
        "--const-rgx=\\b[a-zA-Z_][a-zA-Z0-9_]{0,30}",
        "--function-rgx=\\b[a-zA-Z_][a-zA-Z0-9_]{0,30}",
        "--method-rgx=\\b[a-zA-Z_][a-zA-Z0-9_]{0,30}",
        "--module-rgx=\\b[a-zA-Z_][a-zA-Z0-9_]{0,30}",
        "--variable-rgx=\\b[a-zA-Z_][a-zA-Z0-9_]{0,30}",
        "--inlinevar-rgx=\\b[a-zA-Z_][a-zA-Z0-9_]{0,30}"
    ]

Command used

I have not been able to find the command the extension uses.

Pylint output

Nothing, as it crashes.

Expected behavior

For the linter not to crash

Pylint version

python 3.9.12 <-- my current env. Unsure if the extension uses this
astroid 2.11.2
colorama 0.4.4
dill 0.3.4
isort 5.10.1
lazy_object_proxy 1.7.1
mccabe 0.7.0
packaging 21.3
platformdirs 2.5.1
pydantic 1.8.2
pygls 0.11.3
pylint 2.13.4
pyparsing 3.0.7
tomli 2.0.1
typed_ast 1.5.2
typeguard 2.13.3
typing_extensions 4.1.1
wrapt 1.14

OS / Environment

Windows 10

Pierre-Sassoulas commented 2 years ago

You're using 2.13.4 which is not the last pylint version, could you upgrade pylint and confirm it's still an issue ?

DanielNoord commented 2 years ago

I can't reproduce on main and not with 2.13.4.

Are you sure this is the version that the extension is using? Is it perhaps using a version installed globally? Or in another environment?

timeterror commented 2 years ago

The latest version of the extension uses Pylint 2.13.7 and still shows the same issue

timeterror commented 2 years ago

Running PyLint 2.13.8 from a local env without using the VSCode extension works if I run the following:

pylint --reports=n --output-format=json --max-line-length=100 --disable=C0413,W0105,W0511,W1201,W1202,W1203 --extension-pkg-whitelist=pyodbc,pandas,numpy --ignored-classes=DatetimeIndex,ExtensionIndex,Index --good-names=Run,_ --max-args=25 --ignore-long-lines=^\s*(# )?.*<?https?://\S+>?$|^\s*(\w*\s*=\s*)?("|\').*("|\'),?\s*$ --argument-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --attr-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --class-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --const-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --function-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --method-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --module-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --variable-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --inlinevar-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30}  --from-stdin c:\repos\pipelines\pylint_issue_example.py

So, I am guessing this is more related to the Extension than PyLint.

karthiknadig commented 2 years ago

@timeterror when you run like that pylint does not receive the content. You have to run it like this:

type c:\repos\pipelines\pylint_issue_example.py | pylint --reports=n --output-format=json --max-line-length=100 --disable=C0413,W0105,W0511,W1201,W1202,W1203 --extension-pkg-whitelist=pyodbc,pandas,numpy --ignored-classes=DatetimeIndex,ExtensionIndex,Index --good-names=Run,_ --max-args=25 --ignore-long-lines=^\s*(# )?.*<?https?://\S+>?$|^\s*(\w*\s*=\s*)?("|\').*("|\'),?\s*$ --argument-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --attr-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --class-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --const-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --function-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --method-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --module-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --variable-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --inlinevar-rgx=\b[a-zA-Z_][a-zA-Z0-9_]{0,30} --from-stdin c:\repos\pipelines\pylint_issue_example.py

Also, you can look at the Output > Pylint panel to see details on what is being used to run pylint. including the sys.path.

I tried to reproduce this in the extension, i don't see this occuring: image

jacobtylerwalls commented 2 years ago

The extension will use whatever python interpreter is selected in VS Code. You need to verify which python interpreter that is and make sure you get a python3 -m pip list from that interpreter. I have a hunch that in whatever intepreter that is, astroid is below 2.11. 🤞🏻 (I guess you could verify that pylint chokes when uninstalling astroid from the interpreter you think is being used.)

timeterror commented 2 years ago

First off, my apologies for the slow response, especially with all the help you all have given me.

In any case, I tried to play around with my environments and the vs-code extension but could not find out what was going wrong. Eventually I ended up removing all my envs, uninstalling the extension, and then reinstalling everything. This failed, but repeating this while deleting all the lingering files from my drives before reinstalling everything, it all is working as expected. It is a pity I was unable to pinpoint what exactly is going wrong, but I am certain the issue has nothing to do with pylint itself.

Thank you all for helping.

kingsimba commented 2 years ago

I has similar error. It turns out to be a astroid version mismatch with pylint

$ pylint --version
pylint 2.14.5
astroid 2.9.0
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0]

I compared pylint --version with a partner who has no problem with it. Then I found I have a astroid installed in /home/MY_NAME/.local/lib/python3.8/site-packages.

$ ls ~/.local/lib/python3.8/site-packages
__pycache__
astroid
astroid-2.9.0.dist-info

After uninstalling it, pylint --version is the same as my partner. The problem doesn't exist anymore.

$ pip3 uninstall astroid
$ pyline --version
pylint 2.14.5
astroid 2.11.7
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0]