Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pylint infinite recursion in astriod package

I have a following code snippet, that pylint cannot handle:

from celery import Celery


def create_celery(application):
    """
    Configures celery instance from application, using it's config
    :param application: Flask application instance
    :return: Celery instance
    """
    celery = Celery(application.import_name)
    celery.conf.update(application.config)
    TaskBase = celery.Task

    class ContextTask(TaskBase):
        abstract = True

        def __call__(self, *args, **kwargs):
            with application.app_context():
                return TaskBase.__call__(self, *args, **kwargs)

    celery.Task = ContextTask
    return celery

I get following error:

 File "/usr/local/lib/python3.4/dist-packages/astroid/context.py", line 49, in cache_generator
    for result in generator:
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 302, in wrapped
    for res in _func(node, context, **kwargs):
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 325, in raise_if_nothing_inferred
    for node in func(*args, **kwargs):
  File "/usr/local/lib/python3.4/dist-packages/astroid/inference.py", line 156, in infer_attribute
    for owner in self.expr.infer(context):
  File "/usr/local/lib/python3.4/dist-packages/astroid/context.py", line 49, in cache_generator
    for result in generator:
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 302, in wrapped
    for res in _func(node, context, **kwargs):
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 99, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/usr/local/lib/python3.4/dist-packages/astroid/context.py", line 49, in cache_generator
    for result in generator:
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 302, in wrapped
    for res in _func(node, context, **kwargs):
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 99, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/usr/local/lib/python3.4/dist-packages/astroid/context.py", line 49, in cache_generator
    for result in generator:
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 302, in wrapped
    for res in _func(node, context, **kwargs):
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 325, in raise_if_nothing_inferred
    for node in func(*args, **kwargs):
  File "/usr/local/lib/python3.4/dist-packages/astroid/inference.py", line 100, in infer_call
    for callee in self.func.infer(context):
  File "/usr/local/lib/python3.4/dist-packages/astroid/context.py", line 49, in cache_generator
    for result in generator:
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 302, in wrapped
    for res in _func(node, context, **kwargs):
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 99, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/usr/local/lib/python3.4/dist-packages/astroid/context.py", line 49, in cache_generator
    for result in generator:
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 302, in wrapped
    for res in _func(node, context, **kwargs):
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 99, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/usr/local/lib/python3.4/dist-packages/astroid/context.py", line 49, in cache_generator
    for result in generator:
  File "/usr/local/lib/python3.4/dist-packages/astroid/bases.py", line 302, in wrapped
    for res in _func(node, context, **kwargs):
  File "/usr/local/lib/python3.4/dist-packages/astroid/inference.py", line 144, in infer_import_from
    context = contextmod.copy_context(context)
  File "/usr/local/lib/python3.4/dist-packages/astroid/context.py", line 79, in copy_context
    return context.clone()
  File "/usr/local/lib/python3.4/dist-packages/astroid/context.py", line 42, in clone
    clone = InferenceContext(self.path, inferred=self.inferred)
RuntimeError: maximum recursion depth exceeded

I use latest pylint 1.5.5 and python 3.4

I've tried to contact logilab on issue tracker, but it seems that they have a broken login functionality.

I found a workaround for this, use a --ignore option for that file, but it doesn't solves the problem

like image 724
Nikolai Golub Avatar asked Apr 08 '16 09:04

Nikolai Golub


1 Answers

I had this in my projects and I spent quite a while looking for the problem in astroid. It turned out (for me) that pylint was just deeply recursive and bumping up the stack size solves the problem. So I added the following before the pylint call (I call pylint from unit test code).

# If we don't do this we get stack overflows running pylint!!
# Its parsing and tests are deeply recursive.
import sys
sys.setrecursionlimit(8 * sys.getrecursionlimit())

I have been informed that you can add this to the pylintrc thus (not tested).

init-hook='import sys; sys.setrecursionlimit(8 * sys.getrecursionlimit())'
like image 65
demented hedgehog Avatar answered Sep 26 '22 03:09

demented hedgehog