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

Latest version of astroid (2.6.3) causes RuntimeError: generator raised StopIteration #4723

Closed
bpourhamzeh opened this issue Jul 19, 2021 · 1 comment · Fixed by pylint-dev/astroid#1104
Labels
Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@bpourhamzeh
Copy link

bpourhamzeh commented Jul 19, 2021

Steps to reproduce

mycode.py

import contextlib


class A:
    @contextlib.contextmanager
    def get(self):
        yield self


class B(A):
    def play():
        pass


def func():
    with B().get() as b:
        b.play()

(This is basically from this example: pylint-dev/astroid#1090 except I wrapped the with block in a function.)

Current behavior

(.ve3) bijan@system76-pc:~/pylint_fail$ PYTHONPATH=. pylint -j0 mycode.py
Exception on node <Call l.17 at 0x7f78c97bb0d0> in file '/home/bijan/pylint_fail/mycode.py'
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/protocols.py", line 494, in _infer_context_manager
    yield next(inferred.infer_yield_types())
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/lint/parallel.py", line 69, in _worker_check_single_file
    _worker_linter.check_single_file(name, filepath, modname)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 992, in check_single_file
    self._check_file(
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1033, in _check_file
    check_astroid_module(ast_node)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1170, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 1215, in _check_astroid_module
    walker.walk(ast_node)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  [Previous line repeated 1 more time]
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 74, in walk
    callback(astroid)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 885, in visit_call
    self._check_consider_using_with(node)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/checkers/refactoring/refactoring_checker.py", line 1290, in _check_consider_using_with
    inferred = utils.safe_infer(node.func)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/checkers/utils.py", line 1177, in safe_infer
    value = next(infer_gen)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/node_classes.py", line 354, in infer
    yield from self._infer(context, **kwargs)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/decorators.py", line 100, in wrapped
    res = next(generator)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/inference.py", line 299, in infer_attribute
    for owner in self.expr.infer(context):
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/node_classes.py", line 368, in infer
    for i, result in enumerate(generator):
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/decorators.py", line 100, in wrapped
    res = next(generator)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/bases.py", line 146, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/node_classes.py", line 368, in infer
    for i, result in enumerate(generator):
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/decorators.py", line 97, in wrapped
    generator = _func(node, context, **kwargs)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/inference.py", line 860, in infer_assign
    stmts = list(self.assigned_stmts(context=context))
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/decorators.py", line 136, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/astroid/protocols.py", line 541, in with_assigned_stmts
    yield from _infer_context_manager(self, mgr, context)
RuntimeError: generator raised StopIteration
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/bijan/pylint_fail/.ve3/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/__init__.py", line 24, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/lint/run.py", line 384, in __init__
    linter.check(args)
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/lint/pylinter.py", line 977, in check
    check_parallel(
  File "/home/bijan/pylint_fail/.ve3/lib/python3.8/site-packages/pylint/lint/parallel.py", line 140, in check_parallel
    for (
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 868, in next
    raise value
RuntimeError: generator raised StopIteration

Expected behavior

No exception raised.

pylint --version output

Result of pylint --version output:

(.ve3) bijan@system76-pc:~/pylint_fail$ pylint --version
pylint 2.9.3
astroid 2.6.3
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0]

Additional dependencies:

(.ve3) bijan@system76-pc:~/pylint_fail$ pip freeze
astroid==2.6.3
isort==5.9.2
lazy-object-proxy==1.6.0
mccabe==0.6.1
pkg-resources==0.0.0
pylint==2.9.3
toml==0.10.2
wrapt==1.12.1

There is no issue if I pin to astroid==2.6.2. Also, please let me know if this should be an astroid issue instead.

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.4 milestone Jul 19, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Blocker 🙅 Blocks the next release labels Jul 19, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 19, 2021
Pierre-Sassoulas added a commit to pylint-dev/astroid that referenced this issue Jul 19, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Jul 19, 2021
Pierre-Sassoulas added a commit to pylint-dev/astroid that referenced this issue Jul 19, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Jul 19, 2021
@Pierre-Sassoulas
Copy link
Member

Thank for opening the issue so fast after the release. I missed a next in astroid, it should be fixed in 2.6.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker 🙅 Blocks the next release Crash 💥 A bug that makes pylint crash Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants