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

RecursionError when referencing length/mutating global string #2899

Closed
jpetrucciani opened this issue May 2, 2019 · 2 comments
Closed

RecursionError when referencing length/mutating global string #2899

jpetrucciani opened this issue May 2, 2019 · 2 comments
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash

Comments

@jpetrucciani
Copy link

Steps to reproduce

  1. create a global string
  2. reference it's len/__len__
  3. use that value in a mutation on the global

It appears to only trigger if the reference to len appears on a separate line, and only if the mutation is in place with a slice.

Here's a snippet of code that triggers this issue:

foo = "test"


def broken():
    global foo

    bar = len(foo)
    foo = foo[bar]

Current behavior

RecursionError: maximum recursion depth exceeded with default recursion limit.

Increasing the recursion limit in the .pylintrc file like so:

[MASTER]
init-hook='import sys; sys.setrecursionlimit(100000)'

causes a segfault

Stack trace (truncated in the middle):

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/astroid/__init__.py", line 91, in _inference_tip_cached
    return iter(_cache[func, node])
KeyError: (<function register_builtin_transform.<locals>._transform_wrapper at 0x7f1dac49e840>, <Call l.7 at 0x7f1dabf3b898>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/astroid/__init__.py", line 91, in _inference_tip_cached
    return iter(_cache[func, node])
KeyError: (<function register_builtin_transform.<locals>._transform_wrapper at 0x7f1dac49e840>, <Call l.7 at 0x7f1dabf3b898>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/astroid/__init__.py", line 91, in _inference_tip_cached
    return iter(_cache[func, node])
KeyError: (<function register_builtin_transform.<locals>._transform_wrapper at 0x7f1dac49e840>, <Call l.7 at 0x7f1dabf3b898>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/astroid/__init__.py", line 91, in _inference_tip_cached
    return iter(_cache[func, node])
KeyError: (<function register_builtin_transform.<locals>._transform_wrapper at 0x7f1dac49e840>, <Call l.7 at 0x7f1dabf3b898>)
...
    yield next(generator)
  File "/usr/local/lib/python3.6/site-packages/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/usr/local/lib/python3.6/site-packages/astroid/bases.py", line 137, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/usr/local/lib/python3.6/site-packages/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/usr/local/lib/python3.6/site-packages/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/usr/local/lib/python3.6/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred
    yield next(generator)
  File "/usr/local/lib/python3.6/site-packages/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/usr/local/lib/python3.6/site-packages/astroid/bases.py", line 137, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/usr/local/lib/python3.6/site-packages/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/usr/local/lib/python3.6/site-packages/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/usr/local/lib/python3.6/site-packages/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/usr/local/lib/python3.6/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred
    yield next(generator)
  File "/usr/local/lib/python3.6/site-packages/astroid/inference.py", line 350, in infer_subscript
    for value in self.value.infer(context):
  File "/usr/local/lib/python3.6/site-packages/astroid/util.py", line 160, in limit_inference
    yield from islice(iterator, size)
  File "/usr/local/lib/python3.6/site-packages/astroid/context.py", line 113, in cache_generator
    for result in generator:
  File "/usr/local/lib/python3.6/site-packages/astroid/decorators.py", line 128, in raise_if_nothing_inferred
    generator = func(*args, **kwargs)
RecursionError: maximum recursion depth exceeded while calling a Python object

Expected behavior

Correct pylint analysis with no recursion errors or segfaults

pylint --version output

tried on the following versions:

pylint 2.3.1
astroid 2.2.5
Python 3.7.2 (default, Mar  5 2019, 06:22:51)
[GCC 6.3.0 20170516]
pylint 2.2.2
astroid 2.1.0
Python 3.6.8 (default, Feb  6 2019, 12:07:20)
[GCC 6.3.0 20170516]
pylint 2.3.1
astroid 2.2.5
Python 3.6.8 (default, Feb  6 2019, 12:07:20)
[GCC 6.3.0 20170516]
@PCManticore PCManticore added Bug 🪲 Crash 💥 A bug that makes pylint crash labels May 5, 2019
@PCManticore
Copy link
Contributor

Yikes, thanks for the report @jpetrucciani !

@PCManticore
Copy link
Contributor

Verified that this does not reproduce any longer using the latest astroid and pylint master branches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash
Projects
None yet
Development

No branches or pull requests

2 participants