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 starred_assigned_stmts elts cast (introduced in d68f2935) #842

Merged
merged 1 commit into from Dec 24, 2020
Merged

Fix starred_assigned_stmts elts cast (introduced in d68f2935) #842

merged 1 commit into from Dec 24, 2020

Conversation

vtermanis
Copy link
Contributor

@vtermanis vtermanis commented Sep 17, 2020

Don't replace elts (deque) used in loop with list

Steps

  • For new features or bug fixes, add a ChangeLog entry describing what your PR does.
  • Write a good description on what the PR does.

Description

I recently upgraded pylint (and thus astroid) to: astroid==2.4.2 pylint==2.5.3 (Python 3.8.5) and now I get this exception when running pylint:

  File "/usr/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/lint/check_parallel.py", line 69, in _worker_check_single_file
    _worker_linter.check_single_file(name, filepath, modname)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 889, in check_single_file
    self._check_file(
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 930, in _check_file
    check_astroid_module(ast_node)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1062, in check_astroid_module
    retval = self._check_astroid_module(
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1107, in _check_astroid_module
    walker.walk(ast_node)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 75, in walk
    self.walk(child)
  [Previous line repeated 1 more time]
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 72, in walk
    callback(astroid)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/checkers/typecheck.py", line 1856, in visit_generatorexp
    self._check_iterable(gen.iter, check_async=gen.is_async)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/checkers/typecheck.py", line 1800, in _check_iterable
    inferred = safe_infer(node)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/pylint/checkers/utils.py", line 1119, in safe_infer
    value = next(infer_gen)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/astroid/decorators.py", line 132, in raise_if_nothing_inferred
    yield next(generator)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/astroid/decorators.py", line 96, in wrapped
    res = next(generator)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/astroid/bases.py", line 136, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/astroid/decorators.py", line 132, in raise_if_nothing_inferred
    yield next(generator)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/astroid/decorators.py", line 93, in wrapped
    generator = _func(node, context, **kwargs)
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/astroid/inference.py", line 850, in infer_assign
    stmts = list(self.assigned_stmts(context=context))
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/astroid/decorators.py", line 124, in yes_if_nothing_inferred
    yield from generator
  File "/<SNIP>/.tox/lint/lib/python3.8/site-packages/astroid/protocols.py", line 678, in starred_assigned_stmts
    elts.popleft()
AttributeError: 'list' object has no attribute 'popleft'

(Previously with astroid==2.3.3 pylint==2.4.4 I didn't see this.)

Now I have to admit I haven't look at the astroid codebase before, so I might have got this completely wrong, but:

It appears to me that because of the "cast" of elts from deque to list here, the next time round the outer loop, if there are still more items left in elts, the above exception will trigger. With this patch, pylint runs again successfully for me.

Type of Changes

Type
🐛 Bug fix

Related Issue

Don't replace elts (deque) used in loop with list
@vtermanis
Copy link
Contributor Author

(Rebased against current top of master branch to hopefully make CI pass)

@herve-alanaai
Copy link

Hello, I'm also using astroid 2.4.2 (pylint 2.6.0, python 3.6.12) and I can reproduce the bug described above with this code:

def four_numbers():
    return 1, 2, 3, 4

*prefix, _ = four_numbers()
print(min(*prefix))

Running pylint on that file I get the same exception

  File ".../astroid/protocols.py", line 678, in starred_assigned_stmts
AttributeError: 'list' object has no attribute 'popleft'

The code in this PR fixes the problem for me, thanks!

@PCManticore
Copy link
Contributor

Thanks for the PR.

@PCManticore PCManticore merged commit caa8a64 into pylint-dev:master Dec 24, 2020
@vtermanis vtermanis deleted the fix-starred-assigned-stmts-list branch January 4, 2021 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants