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

pylint exceed maximum recursion depth #2388

Closed
skirpichev opened this issue Aug 7, 2018 · 22 comments
Closed

pylint exceed maximum recursion depth #2388

skirpichev opened this issue Aug 7, 2018 · 22 comments
Labels

Comments

@skirpichev
Copy link
Contributor

There are similar errors in bugtracker, e.g. #1410, #1285, but I'm not sure the underlying reason for this issue is same.

Steps to reproduce

  1. python3 -m venv ~/venv/pylint-test
  2. . ~/venv/pylint-test/bin/activate
  3. Follow http://diofant.readthedocs.io/en/latest/install.html#from-sources
  4. run pylint --enable=old-raise-syntax diofant/solvers/recurr.py

Current behavior

It fails with

internal error with sending report for module ['diofant/solvers/recurr.py']
maximum recursion depth exceeded

Expected behavior

No internal error.

pylint --version output

pylint 2.1.0
astroid 2.0.2
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118]

Some debugging

Note, that same error happens if you enable different checker instead, almost any disabled. For example, exception-message-attribute. The internal error disappears if I comment out line 527.

@brycepg brycepg added Bug 🪲 Astroid Related to astroid labels Aug 7, 2018
@brycepg
Copy link
Contributor

brycepg commented Aug 8, 2018

Here's my somewhat easier reproduction:

  1. Install diofant
  2. Save the following code in a file named file.py
from diofant.simplify import hypersimp, simplify

def rsolve_hyper():
    b = simplify(g)
    s = hypersimp(b, n)
    s.subs()
  1. Run
    pylint -j1 -rn -sn --enable=all file.py

The -j1 option makes pylint use a single threaded reporter which shows the traceback:

  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/__main__.py", line 7, in <module>
    pylint.run_pylint()
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/__init__.py", line 19, in run_pylint
    Run(sys.argv[1:])
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/lint.py", line 1394, in __init__
    linter.check(args)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/lint.py", line 801, in check
    self._do_check(files_or_modules)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/lint.py", line 938, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/lint.py", line 1018, in check_astroid_module
    walker.walk(ast_node)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/utils.py", line 1162, in walk
    self.walk(child)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/utils.py", line 1162, in walk
    self.walk(child)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/utils.py", line 1162, in walk
    self.walk(child)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/utils.py", line 1159, in walk
    cb(astroid)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 961, in visit_call
    inferred = utils.safe_infer(node.func)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/pylint/checkers/utils.py", line 828, in safe_infer
    value = next(inferit)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/inference.py", line 293, in infer_attribute
    for owner in self.expr.infer(context):
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/bases.py", line 125, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/bases.py", line 125, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/inference.py", line 219, in infer_call
    context=callcontext,
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 1628, in infer_call_result
    yield from returnnode.value.infer(context)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/inference.py", line 219, in infer_call
    context=callcontext,
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 1628, in infer_call_result
    yield from returnnode.value.infer(context)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/inference.py", line 211, in infer_call
    for callee in self.func.infer(context):
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/util.py", line 148, in limit_inference
    yield from islice(iterator, size)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/context.py", line 107, in cache_generator
    for result in generator:
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 92, in wrapped
    res = next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/decorators.py", line 125, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/inference.py", line 293, in infer_attribute
...
    context = contextmod.copy_context(context)
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/context.py", line 146, in copy_context
    return context.clone()
  File "/home/user/venv/pylint-issue-2388/lib/python3.6/site-packages/astroid/context.py", line 96, in clone
    clone = InferenceContext(copy.copy(self.path), inferred=self.inferred)
RecursionError: maximum recursion depth exceeded

@brycepg
Copy link
Contributor

brycepg commented Aug 8, 2018

So it looks like this is just a stack limit issue (is not infinite recursion). The only way to reproduce this issue without pylint is to add extra calls to the call stack:

import astroid

def f():
    return astroid.extract_node("""
    from diofant.simplify import hypersimp, simplify
    def rsolve_hyper():
        b = simplify(g)
        s = hypersimp(b, n)
        s.subs() #@
    """).inferred()

def a(n=5):
    if n > 0:
        return a(n-1)
    else:
        return f()
a()

I think I might merge a few astroid calls to lower the stack size

@brycepg
Copy link
Contributor

brycepg commented Aug 10, 2018

I fixed this issue on a local branch, but running pylint on this package didn't complete even overnight.. Not sure if the fix is worth it -- I think astroid has some perf issues with complex class hierarchies

(see https://github.com/brycepg/astroid/tree/inline-calls)

@PCManticore
Copy link
Contributor

We probably need to figure out what's the root cause of this problem. As Bryce mentioned, pylint is not even able to complete in a reasonable amount of time. I've tried increasing the recursion limit with --init-hook="import sys; sys.setrecursionlimit(2000)" and pylint gets stuck.

@skirpichev
Copy link
Contributor Author

I've tried increasing the recursion limit with --init-hook="import sys; sys.setrecursionlimit(2000)" and pylint gets stuck.

Is this for whole project tree?

I have tried original example from bugreport (for diofant/solvers/recurr.py) with increased recursion limit (as you suggested, with --init-hook) and the test pass (it's slow, but not hangs forever).

@PCManticore
Copy link
Contributor

Just for the original example. I stopped it after a couple of minutes, maybe it would have completed later on.

@dragoljub
Copy link

I'm seeing the same issue on Python 3.7 and Windows 10 in VS Code. Any ideas how to resolve?

@tomarharsh
Copy link

Same issue with Python 3.7, Mojave 10.14, VS Code.

@LuoPengFei
Copy link

Same issue with Python 3.7, VS Code 1.36.1 (1.36.1), Mojave 10.14.5

@karlicoss
Copy link

I'm running into that with the following code snippet:

import pandas as pd
df = pd.merge(df)

Astroid 1.4.1; pylint 2.3.1

@corndog2000
Copy link

Same error message with Python 3.7.3, Ubuntu 18.04.2, VS Code 1.36.1.

Picture of error: https://imgur.com/a/PTNkteD

@dragoljub
Copy link

My issue was resolved on Python 3.7.1 after upgrading to these versions:
astroid 2.2.5
pylint 2.3.1

abhinav-upadhyay added a commit to ApptuitAI/apptuit-py that referenced this issue Oct 18, 2019
@andreasvc
Copy link

FWIW, I think I encountered the same or a similar bug.

In my case, I tracked down that the problem was with the option --extension-pkg-whitelist=[...]. If numpy is included in this list, the issue occurs, if I leave it out, it's gone.

andreasvc added a commit to andreasvc/disco-dop that referenced this issue Oct 24, 2019
- use pycodestyle instead of pep8
- disable import-outside-toplevel
- remove numpy from whitelist because of pylint issue
  pylint-dev/pylint#2388
@dragoljub
Copy link

dragoljub commented Oct 24, 2019

Thanks for the tip. I actually had that setting before and still keep it on. --extension-pkg-whitelist=numpy

However, after upgrading to later versions of python and pylint and astroid I no longer have the issue even with the numpy whitelist setting.

Python 3.7.1
pylint 2.3.1
astroid 2.2.5

@feliwir
Copy link

feliwir commented Jan 15, 2020

Any updates on how to get rid of this issue?

@ashkan-leo
Copy link

Any update on how to solve this issue?

@PCManticore
Copy link
Contributor

The original issue is no longer reproduceable with the following versions, installed from master branch for both pylint and astroid:

pylint 2.5.0-dev1
astroid 2.4.0
Python 3.8.1 (default, Feb 13 2020, 10:17:07)
[Clang 8.1.0 (clang-802.0.42)]

It's also no longer reproduceable with the already released versions of pylint 2.4.4 and astroid 2.3.3.

@skirpichev Please give it a go with the aforementioned versions and let us know if you can still reproduce the issue.

For other folks commenting here, if your issue is not related to diophant, please submit a separate one. Thanks!

@dickreuter
Copy link
Contributor

dickreuter commented Dec 15, 2020

The issue is definitely not resolved, neither for 2.4.4, nor for 2.3.1 nor for 2.6. The only way to solve the problem is to downgrade Astroid to 2.2.5. Otherwise the problem occurs intermittently, which makes it hard to reproduce on a permanent basis.

@ohaibbq
Copy link

ohaibbq commented Dec 15, 2020

I'm also seeing the behavior with pylint==2.6.0 & astroid==2.4.2.

@Yevgnen
Copy link

Yevgnen commented Dec 17, 2020

Facing the same issue with

pylint 2.6.0 python code static checker
├── astroid >=2.4.0,<=2.5
│   ├── lazy-object-proxy >=1.4.0,<1.5.0
│   ├── six >=1.12,<2.0
│   └── wrapt >=1.11,<2.0
├── colorama *
├── isort >=4.2.5,<6
├── mccabe >=0.6,<0.7
└── toml >=0.7.1

@hippo91
Copy link
Contributor

hippo91 commented Dec 20, 2020

@dickreuter can you please open a different issue with a reproducer in it please?

@summer-via
Copy link

I upgrade pylint from 2.5.3 to 2.14.1, then it is solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests