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

Tuple packing/unpacking in assignment crashes pylint #3968

Closed roey-e closed 3 years ago

roey-e commented 3 years ago

Steps to reproduce

  1. Clone https://github.com/roey-e/unlintable (install a virtual environment with pylint)
  2. pylint unlintable.py

The code:

"""This file is unlintable."""

from typing import Tuple

def get_numbers() -> Tuple[int, int, int, int]:
    """Returns four numbers."""

    return 1, 2, 3, 4

def take_numbers(first: int, second: int, third: int, fourth: int) -> None:
    """Takes four numbers."""

    print(first+second+third+fourth)

def unlintable() -> None:
    """This function is unlintable."""

    *numbers, fourth = get_numbers()
    take_numbers(*numbers, fourth + 100)

if __name__ == "__main__":
    unlintable()

Current behavior

Exception is raised

(project-Z16mBerO-py3.7) roey@penguin:~/project$ pylint unlintable.py 
Traceback (most recent call last):
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/lint/run.py", line 349, in __init__
    linter.check(args)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 863, in check
    self.get_ast, self._iterate_file_descrs(files_or_modules)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 896, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 922, in _check_file
    check_astroid_module(ast_node)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 1055, in check_astroid_module
    ast_node, walker, rawcheckers, tokencheckers
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/lint/pylinter.py", line 1099, in _check_astroid_module
    walker.walk(ast_node)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/pylint/checkers/typecheck.py", line 1259, in visit_call
    call_site = astroid.arguments.CallSite.from_call(node)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/arguments.py", line 66, in from_call
    return cls(callcontext, context=context)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/arguments.py", line 42, in __init__
    self._unpacked_args = self._unpack_args(args, context=context)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/arguments.py", line 135, in _unpack_args
    inferred = next(arg.value.infer(context=context))
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/decorators.py", line 132, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/decorators.py", line 96, in wrapped
    res = next(generator)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/bases.py", line 136, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/decorators.py", line 132, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/decorators.py", line 93, in wrapped
    generator = _func(node, context, **kwargs)
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/inference.py", line 850, in infer_assign
    stmts = list(self.assigned_stmts(context=context))
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/decorators.py", line 124, in yes_if_nothing_inferred
    yield from generator
  File "/home/roey/.cache/pypoetry/virtualenvs/project-Z16mBerO-py3.7/lib/python3.7/site-packages/astroid/protocols.py", line 678, in starred_assigned_stmts
    elts.popleft()
AttributeError: 'list' object has no attribute 'popleft'

Expected behavior

Regular pylint output.

pylint --version output

(project-Z16mBerO-py3.7) roey@penguin:~/project$ pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0]
dbaty commented 3 years ago

Minimal failing code that fails on Python 3.8 and the current master branches of pylint and astroid:

*rest, a = [1, 2]
print(*rest)

This is a bug in Astroid, where it has in fact already been reported: PyCQA/astroid/pull/842

PCManticore commented 3 years ago

I can no longer reproduce this after https://github.com/PyCQA/astroid/pull/842 has been merged.