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.31k stars 1.13k forks source link

AttributeError: 'NoneType' object has no attribute 'frame' #3991

Closed scorpp closed 3 years ago

scorpp commented 3 years ago

Steps to reproduce

from openpyxl import Workbook
from openpyxl.worksheet.table import Table, TableStyleInfo

if __name__ == '__main__':
    wb = Workbook()
    ws = wb.create_sheet('Sheet name')
    table_style = TableStyleInfo(
        name='TableStyleMedium9',
        showFirstColumn=False,
        showLastColumn=False,
        showRowStripes=True,
    )
    data_table1 = Table(
        name=f'Data',
        displayName=f'Data',
        ref=f'A2:C4',
        tableStyleInfo=table_style,
    )
    ws.add_table(data_table1)   # this line causes error

Current behavior

$ pylint pylint_test.py 
Traceback (most recent call last):
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/lint/run.py", line 358, in __init__
    linter.check(args)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 863, in check
    self.get_ast, self._iterate_file_descrs(files_or_modules)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 896, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 922, in _check_file
    check_astroid_module(ast_node)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 1055, in check_astroid_module
    ast_node, walker, rawcheckers, tokencheckers
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 1099, in _check_astroid_module
    walker.walk(ast_node)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/checkers/strings.py", line 416, in visit_call
    func = utils.safe_infer(node.func)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/checkers/utils.py", line 1147, in safe_infer
    inferred_types.add(_get_python_type_of_node(value))
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/pylint/checkers/utils.py", line 1126, in _get_python_type_of_node
    return pytype()
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 1185, in pytype
    if "method" in self.type:
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/astroid/decorators.py", line 72, in __get__
    val = self.wrapped(inst)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 1462, in type
    for decorator in self.extra_decorators:
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/astroid/decorators.py", line 72, in __get__
    val = self.wrapped(inst)
  File "/home/user/.local/share/virtualenvs/VjPnRKx6/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 1419, in extra_decorators
    frame = self.parent.frame()
AttributeError: 'NoneType' object has no attribute 'frame'

Expected behavior

pylint doesn't crash

pylint --version output

Latest pylint & astroid from master branches. Also reproduces with latest release versions (2.6.0 & 2.4.2)

pylint 2.6.1-dev1
astroid 2.5.0
Python 3.6.8 (default, Feb 11 2019, 08:59:55) 
[GCC 8.2.1 20181127]
hippo91 commented 3 years ago

@scorpp thank for your report. I'm unable to reproduce it. I'v linted the following code:

from openpyxl import Workbook
from openpyxl.worksheet.table import Table, TableStyleInfo

if __name__ == '__main__':
    wb = Workbook()
    ws = wb.create_sheet('Sheet name')
    table_style = TableStyleInfo(
        name='TableStyleMedium9',
        showFirstColumn=False,
        showLastColumn=False,
        showRowStripes=True,
    )
    data_table1 = Table(
        name=f'Data',
        displayName=f'Data',
        ref=f'A2:C4',
        tableStyleInfo=table_style,
    )
    ws.add_table(data_table1)   # this line causes error

in two different virtual environments (python 3.6.9 and python 3.7.9 with various branches of pylint and astroid. None of them triggered the problem your are facing. I got:

************* Module bug_pylint_3991
bug_pylint_3991.py:1:0: C0114: Missing module docstring (missing-module-docstring)
bug_pylint_3991.py:14:13: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
bug_pylint_3991.py:15:20: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)
bug_pylint_3991.py:16:12: W1309: Using an f-string that does not have any interpolated variables (f-string-without-interpolation)

------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 5.00/10, +0.00)

with:

pylint 2.6.0
astroid 2.4.2
Python 3.6.9 (default, Dec 28 2020, 18:50:27) 
[GCC 7.5.0]

or

pylint 2.6.0
astroid 2.4.2
Python 3.7.9 (default, Dec 19 2020, 14:12:54) 
[GCC 7.5.0]

or even:

pylint 2.6.1-dev1
astroid 2.5.0
Python 3.6.9 (default, Dec 28 2020, 18:50:27) 
[GCC 7.5.0]

Maybe the issue is linked to the version of openpyxl. In all cases i used 3.0.5.

PCManticore commented 3 years ago

The output looks extremely similar to https://github.com/PyCQA/astroid/issues/819. I bet it's the same root cause, a missing parent in dunder method inference. @scorpp If you are able to test with the latest version of astroid from its master branch against your code, that would be great. I think it will pass with the latest, but let us know if not and we'll reopen the ticket.

scorpp commented 3 years ago

@hippo91 you were right regarding the openpyxl! I was able to reproduce the issue with astroid==2.4.0 and openpyxl==2.6.1.

but at same time i can confirm that astroid version from master fixes this issue!

thank you guys for looking into this and maintaining great tool! issue resolved.