Pylint: RuntimeError: generator raised StopIteration

Created on 18 Jul 2018  ·  14Comments  ·  Source: PyCQA/pylint

Steps to reproduce

  1. pylint

Current behavior

Traceback (most recent call last):
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/protocols.py", line 306, in _arguments_infer_argname
    context.extra_context)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/arguments.py", line 31, in __init__
    self._unpacked_kwargs = self._unpack_keywords(keywords)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/arguments.py", line 77, in _unpack_keywords
    inferred = next(value.infer(context=context))
StopIteration

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

Traceback (most recent call last):
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/bin/pylint", line 11, in <module>
    sys.exit(run_pylint())
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/pylint/__init__.py", line 19, in run_pylint
    Run(sys.argv[1:])
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/pylint/lint.py", line 1394, in __init__
    linter.check(args)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/pylint/lint.py", line 801, in check
    self._do_check(files_or_modules)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/pylint/lint.py", line 938, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/pylint/lint.py", line 1018, in check_astroid_module
    walker.walk(ast_node)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/pylint/utils.py", line 1159, in walk
    self.walk(child)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/pylint/utils.py", line 1159, in walk
    self.walk(child)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/pylint/utils.py", line 1159, in walk
    self.walk(child)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/pylint/utils.py", line 1156, in walk
    cb(astroid)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/pylint/checkers/typecheck.py", line 1349, in visit_subscript
    inferred = safe_infer(node.value)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/pylint/checkers/utils.py", line 812, in safe_infer
    next(inferit)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/decorators.py", line 84, in wrapped
    res = next(generator)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/bases.py", line 113, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/util.py", line 144, in limit_inference
    yield from islice(iterator, size)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/context.py", line 103, in cache_generator
    for result in generator:
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/decorators.py", line 84, in wrapped
    res = next(generator)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/bases.py", line 113, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/util.py", line 144, in limit_inference
    yield from islice(iterator, size)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/context.py", line 103, in cache_generator
    for result in generator:
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/decorators.py", line 123, in raise_if_nothing_inferred
    yield next(generator)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/decorators.py", line 84, in wrapped
    res = next(generator)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/inference.py", line 197, in infer_call
    context=callcontext,
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 1609, in infer_call_result
    yield from returnnode.value.infer(context)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/util.py", line 144, in limit_inference
    yield from islice(iterator, size)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/context.py", line 103, in cache_generator
    for result in generator:
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/decorators.py", line 84, in wrapped
    res = next(generator)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/bases.py", line 113, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/util.py", line 144, in limit_inference
    yield from islice(iterator, size)
  File "/Users/MYSELF/Sites/MYSITE/MYSITEenv/lib/python3.7/site-packages/astroid/context.py", line 103, in cache_generator
    for result in generator:
RuntimeError: generator raised StopIteration

Expected behavior

Report as normal.

pylint --version output

pylint 2.0.0
astroid 2.0.0.dev4
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)]
astroid bug python 3.7

All 14 comments

Does this still occur after fully upgrading both astroid and pylint?: pip install --upgrade astroid pylint (since your astroid version is out of date)

If it's still reproducable, can you provide a minimal, verifiable example?

Yes, it claim latest versions are installed. I will try to get it down to class/method but probably only tomorrow. Will also try to rebuild virtualenv from scratch. There is only one, single file in whole project that fails like this.

Actually, it was easier than I thought:

from django.views.generic import TemplateView


class DVM(TemplateView):
    def get_context_data(self, **kwargs):
        ctx = super().get_context_data(**kwargs)
        return ctx


class IFDVM(DVM):
    def get_context_data(self, **kwargs):
        ctx = super().get_context_data(**kwargs)
        ctx['bar'] = 'foo'
        return ctx

is enough to trigger same exception. Without ctx['bar'] = 'foo' in inheriting class it works fine.

In terms of astroid, whatever I try to do it always pulls version 2.0, which gets reported by pylint as 2.0.0.dev4.

If you look in pip freeze it looks like the astroid version is correctly 2.0.0, but pylint is just misreporting the version as 2.0.0dev4 somehow.

I can reproduce; this bug only occurs with Python 3.7

pip freeze:

-e [email protected]:brycepg/astroid.git@05e94e94c5428a277bbb578c91f9c4ae6f9c6c79#egg=astroid
Django==2.0.7
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
-e [email protected]:/brycepg/pylint.git@d645d2cb1720c3018fa663e8bff01880703a8861#egg=pylint
pytz==2018.5
six==1.11.0
wrapt==1.10.11

Here's a reproduction without django:

class ContextMixin:
    def get_context_data(self, **kwargs):
        return kwargs


class DVM(ContextMixin):
    def get_context_data(self, **kwargs):
        ctx = super().get_context_data(**kwargs)
        return ctx


class IFDVM(DVM):
    def get_context_data(self, **kwargs):
        ctx = super().get_context_data(**kwargs)
        ctx['bar'] = 'foo'
        return ctx

Even simpler way to reproduce
```# pylint test.py
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 89, in wrapped
res = next(generator)
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 104, in wrapped
raise StopIteration
StopIteration

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

Traceback (most recent call last):
File "/usr/local/bin/pylint", line 11, in
sys.exit(run_pylint())
File "/usr/local/lib/python3.7/site-packages/pylint/__init__.py", line 16, in run_pylint
Run(sys.argv[1:])
File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 1347, in __init__
linter.check(args)
File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 768, in check
self._do_check(files_or_modules)
File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 901, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/usr/local/lib/python3.7/site-packages/pylint/lint.py", line 980, in check_astroid_module
walker.walk(ast_node)
File "/usr/local/lib/python3.7/site-packages/pylint/utils.py", line 1014, in walk
self.walk(child)
File "/usr/local/lib/python3.7/site-packages/pylint/utils.py", line 1011, in walk
cb(astroid)
File "/usr/local/lib/python3.7/site-packages/pylint/checkers/variables.py", line 1260, in visit_importfrom
module = node.do_import_module(name_parts[0])
File "/usr/local/lib/python3.7/site-packages/astroid/mixins.py", line 119, in do_import_module
relative_only=level and level >= 1)
File "/usr/local/lib/python3.7/site-packages/astroid/scoped_nodes.py", line 593, in import_module
return MANAGER.ast_from_module_name(absmodname)
File "/usr/local/lib/python3.7/site-packages/astroid/manager.py", line 154, in ast_from_module_name
return self.ast_from_file(found_spec.location, modname, fallback=False)
File "/usr/local/lib/python3.7/site-packages/astroid/manager.py", line 80, in ast_from_file
return AstroidBuilder(self).file_build(filepath, modname)
File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 153, in file_build
return self._post_build(module, encoding)
File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 173, in _post_build
self.delayed_assattr(delayed)
File "/usr/local/lib/python3.7/site-packages/astroid/builder.py", line 232, in delayed_assattr
for inferred in node.expr.infer():
File "/usr/local/lib/python3.7/site-packages/astroid/decorators.py", line 89, in wrapped
res = next(generator)
File "/usr/local/lib/python3.7/site-packages/astroid/bases.py", line 95, in _infer_stmts
for inferred in stmt.infer(context=context):
File "/usr/local/lib/python3.7/site-packages/astroid/context.py", line 71, in cache_generator
for result in generator:
RuntimeError: generator raised StopIteration

pylint --version

pylint 1.9.2,
astroid 1.6.5
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)]

cat test.py

from enum import Enum```

Upgrading to astroid 2.0 fixed my issue
pip install -U astroid

● pylint test2.py
************* Module test2
test2.py:1:0: W0611: Unused Enum imported from enum (unused-import)

-----------------------------------
Your code has been rated at 0.00/10

● cat test2.py
from enum import Enum

Correct, doesn't error on 2.0.0 (astroid) - must be different issue then.

Just upgraded astroid, but still getting the same error.

pylint 2.0.0
astroid 2.0.1
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)]

With next versions everything works fine for me:
```Using config file /Users/paul/.pylintrc
pylint 1.9.2,
astroid 2.0.0.dev4
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)]

This issue concerns pylint 2.0.0.

Issue still present on:

pylint 2.0.1
astroid 2.0.1
Python 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)]

My PR to fix this is still in the process of being reviewed

Was this page helpful?
0 / 5 - 0 ratings