Skip to content

RuntimeError: generator raised StopIteration  #762

@JustKiddingCode

Description

@JustKiddingCode

I have the error bellow when using dataclasses with replace and pylint.
I think it has something todo with the key access, when I'm using a normal (emtpy) dict
pylint doesn't throw an error.

Steps to reproduce

Use this example:

from dataclasses import dataclass, field, replace
from typing import List

def default_redirect():
    return []

@dataclass
class ProxyConfig:
    """ Configuration for the Proxy Setup """
    keyfile: str
    certfile: str
    domainname: str
    contacts: List[str]
    address: str = "0.0.0.0"
    tls_port: int = 443
    plain_port: int = 80
    https_only: bool = True
    username: str = "www-data"
    groupname: str = "www-data"
    secrets: str = "/var/lib/oidc-proxy/secrets.yml"
    tls_redirect: str = "/TLSRedirect"
    auth: str = "/auth"
    redirect: List[str] = field(default_factory=default_redirect)
    plugin_dirs: List[str] = field(default_factory=list)


a = ProxyConfig("", "", "", [""])
test_dict = {"proxy" : {}}

a = replace(a, **test_dict['proxy'])

Run with pylint

Current behavior

************* Module test
/tmp/tmp.9j0R7c2kjs/test.py:1:0: C0114: Missing module docstring (missing-module-docstring)
/tmp/tmp.9j0R7c2kjs/test.py:4:0: C0116: Missing function or method docstring (missing-function-docstring)
/tmp/tmp.9j0R7c2kjs/test.py:7:0: R0902: Too many instance attributes (15/7) (too-many-instance-attributes)
Traceback (most recent call last):
  File "/home/justkidding/git/astroid/astroid/protocols.py", line 337, in _arguments_infer_argname
    call_site = arguments.CallSite(context.callcontext, context.extra_context)
  File "/home/justkidding/git/astroid/astroid/arguments.py", line 43, in __init__
    self._unpacked_kwargs = self._unpack_keywords(keywords, context=context)
  File "/home/justkidding/git/astroid/astroid/arguments.py", line 96, 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 "/home/justkidding/.local/share/virtualenvs/pylint-b0C_0gT4/bin/pylint", line 7, in <module>
    exec(compile(f.read(), __file__, 'exec'))
  File "/home/justkidding/git/pylint/bin/pylint", line 4, in <module>
    run_pylint()
  File "/home/justkidding/git/pylint/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/home/justkidding/git/pylint/pylint/lint.py", line 1770, in __init__
    linter.check(args)
  File "/home/justkidding/git/pylint/pylint/lint.py", line 980, in check
    self._check_files(self.get_ast, self._iterate_file_descrs(files_or_modules))
  File "/home/justkidding/git/pylint/pylint/lint.py", line 1009, in _check_files
    self._check_file(get_ast, check_astroid_module, name, filepath, modname)
  File "/home/justkidding/git/pylint/pylint/lint.py", line 1035, in _check_file
    check_astroid_module(ast_node)
  File "/home/justkidding/git/pylint/pylint/lint.py", line 1168, in check_astroid_module
    ast_node, walker, rawcheckers, tokencheckers
  File "/home/justkidding/git/pylint/pylint/lint.py", line 1212, in _check_astroid_module
    walker.walk(ast_node)
  File "/home/justkidding/git/pylint/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/home/justkidding/git/pylint/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/home/justkidding/git/pylint/pylint/utils/ast_walker.py", line 74, in walk
    callback(astroid)
  File "/home/justkidding/git/pylint/pylint/checkers/base.py", line 1938, in visit_assignname
    if isinstance(utils.safe_infer(assign_type.value), astroid.ClassDef):
  File "/home/justkidding/git/pylint/pylint/checkers/utils.py", line 1105, in safe_infer
    for inferred in infer_gen:
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 141, in raise_if_nothing_inferred
    yield from generator
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/home/justkidding/git/astroid/astroid/inference.py", line 229, in infer_call
    yield from callee.infer_call_result(caller=self, context=callcontext)
  File "/home/justkidding/git/astroid/astroid/scoped_nodes.py", line 1706, in infer_call_result
    yield from returnnode.value.infer(context)
  File "/home/justkidding/git/astroid/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/home/justkidding/git/astroid/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 141, in raise_if_nothing_inferred
    yield from generator
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/home/justkidding/git/astroid/astroid/inference.py", line 223, in infer_call
    for callee in self.func.infer(context):
  File "/home/justkidding/git/astroid/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/home/justkidding/git/astroid/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 141, in raise_if_nothing_inferred
    yield from generator
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/home/justkidding/git/astroid/astroid/inference.py", line 289, in infer_attribute
    for owner in self.expr.infer(context):
  File "/home/justkidding/git/astroid/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/home/justkidding/git/astroid/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 141, in raise_if_nothing_inferred
    yield from generator
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/home/justkidding/git/astroid/astroid/bases.py", line 132, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/justkidding/git/astroid/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/home/justkidding/git/astroid/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 131, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/home/justkidding/git/astroid/astroid/bases.py", line 132, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/justkidding/git/astroid/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/home/justkidding/git/astroid/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 131, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/home/justkidding/git/astroid/astroid/inference.py", line 223, in infer_call
    for callee in self.func.infer(context):
  File "/home/justkidding/git/astroid/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/home/justkidding/git/astroid/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 131, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/home/justkidding/git/astroid/astroid/inference.py", line 289, in infer_attribute
    for owner in self.expr.infer(context):
  File "/home/justkidding/git/astroid/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/home/justkidding/git/astroid/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 131, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/home/justkidding/git/astroid/astroid/bases.py", line 132, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/justkidding/git/astroid/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/home/justkidding/git/astroid/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/home/justkidding/git/astroid/astroid/decorators.py", line 131, in raise_if_nothing_inferred
    yield next(generator)
RuntimeError: generator raised StopIteration

Expected behavior

No stacktrace.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

2.4.0 (git master), but also 2.3.X

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions