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 RecursionError on array slicing examples #2734

Closed
ghost opened this issue Feb 8, 2019 · 1 comment · Fixed by pylint-dev/astroid#660
Closed

pylint RecursionError on array slicing examples #2734

ghost opened this issue Feb 8, 2019 · 1 comment · Fixed by pylint-dev/astroid#660
Assignees
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash

Comments

@ghost
Copy link

ghost commented Feb 8, 2019

Pylint crashes with RecursionError if called (without special arguments or pylintrc) on following examples:

Example A ('a' from global scope)

Step 1 - A.py:

a = []


def f():
    global a

    l = len(a)
    a = [1, 2, 3][:l]  # ``l`` may not occur in the slice

Step 2 - pylint A.py

Example B ('a' from class scope)

Step 1 - B.py:

class A():
    a = []

    def f(self):
        l = len(self.a)
        self.a = [1, 2, 3][:l]

Step 2 - pylint B.py

Current behavior

Pylint crashes with both examples. Console output (for example A only):

************* Module A
A.py:11:0: C0305: Trailing newlines (trailing-newlines)
A.py:1:0: C0103: Module name "A" doesn't conform to snake_case naming style (invalid-name)
A.py:1:0: C0111: Missing module docstring (missing-docstring)
A.py:3:0: C0103: Constant name "a" doesn't conform to UPPER_CASE naming style (invalid-name)
A.py:6:0: C0103: Function name "f" doesn't conform to snake_case naming style (invalid-name)
A.py:6:0: C0111: Missing function docstring (missing-docstring)
A.py:7:4: W0603: Using the global statement (global-statement)
A.py:7:4: C0103: Constant name "a" doesn't conform to UPPER_CASE naming style (invalid-name)
Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/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 0x7f2631245ae8>, <Call l.9 at 0x7f2630b093c8>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/bin/pylint", line 10, in <module>
    sys.exit(run_pylint())
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/__init__.py", line 20, in run_pylint
    Run(sys.argv[1:])
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/lint.py", line 1610, in __init__
    linter.check(args)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/lint.py", line 936, in check
    self._do_check(files_or_modules)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/lint.py", line 1068, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/lint.py", line 1151, in check_astroid_module
    walker.walk(ast_node)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/utils.py", line 1303, in walk
    self.walk(child)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/utils.py", line 1303, in walk
    self.walk(child)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/utils.py", line 1303, in walk
    self.walk(child)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/utils.py", line 1300, in walk
    cb(astroid)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/checkers/base.py", line 1755, in visit_assignname
    self._check_name("variable", node.name, node)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/checkers/base.py", line 1810, in _check_name
    if match is None and not _should_exempt_from_invalid_name(node):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/checkers/base.py", line 1786, in _should_exempt_from_invalid_name
    inferred = utils.safe_infer(node)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/pylint/checkers/utils.py", line 1061, in safe_infer
    value = next(inferit)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/astroid/decorators.py", line 131, in raise_if_nothing_inferred
    yield next(generator)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/astroid/decorators.py", line 95, in wrapped
    res = next(generator)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/astroid/bases.py", line 137, in _infer_stmts
    for inferred in stmt.infer(context=context):
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/astroid/node_classes.py", line 348, in infer
    return self._explicit_inference(self, context, **kwargs)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/astroid/__init__.py", line 93, in _inference_tip_cached
    result = func(*args, **kwargs)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/astroid/brain/brain_builtin_inference.py", line 130, in _transform_wrapper
    result = transform(node, context=context)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/astroid/brain/brain_builtin_inference.py", line 674, in infer_len
    return nodes.Const(helpers.object_len(argument_node))
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/astroid/helpers.py", line 245, in object_len
    inferred_node = safe_infer(node, context=context)
  File "/home/astro/Projects/EdgeQAM_64Ch/venv/lib/python3.5/site-packages/astroid/helpers.py", line 153, in safe_infer
    value = next(inferit)
(...) the last lines repeat 

Expected behavior

Should show linter warnings, but should not crash.

pylint --version output

pylint 2.3.0-dev1
astroid 2.2.0-dev
Python 3.5.5 (default, Jun 22 2018, 07:48:18) 
[GCC 4.8.4]
@PCManticore
Copy link
Contributor

Thanks for reporting the issue!

@PCManticore PCManticore added Bug 🪲 Crash 💥 A bug that makes pylint crash labels Feb 11, 2019
@brycepg brycepg self-assigned this Mar 30, 2019
brycepg added a commit to brycepg/astroid that referenced this issue Mar 30, 2019
The dropped context was causing InferenceErrors
in self referential assignment

Example:

    self.a = len(self.a)

There is a bigger problem of inference not understanding control flow
that this fix does not solve.

Close pylint-dev/pylint#2736
Close pylint-dev/pylint#2734
Close pylint-dev/pylint#2740
brycepg added a commit to brycepg/astroid that referenced this issue Mar 30, 2019
The dropped context was causing RecursionErrors
in self referential assignment

Example:

    self.a = len(self.a)

There is a bigger problem of inference not understanding control flow
that this fix does not solve.

Close pylint-dev/pylint#2736
Close pylint-dev/pylint#2734
Close pylint-dev/pylint#2740
brycepg added a commit to brycepg/astroid that referenced this issue Mar 30, 2019
The dropped context was causing RecursionErrors
in self referential assignment

Example:

    self.a = len(self.a)

There is a bigger problem of inference not understanding control flow
that this fix does not solve.

Close pylint-dev/pylint#2736
Close pylint-dev/pylint#2734
Close pylint-dev/pylint#2740
PCManticore pushed a commit to pylint-dev/astroid that referenced this issue Apr 1, 2019
The dropped context was causing RecursionErrors
in self referential assignment

Example:

    self.a = len(self.a)

There is a bigger problem of inference not understanding control flow
that this fix does not solve.

Close pylint-dev/pylint#2736
Close pylint-dev/pylint#2734
Close pylint-dev/pylint#2740
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

Successfully merging a pull request may close this issue.

2 participants