pylint-dev / astroid

A common base representation of python source code for pylint and other projects
https://pylint.readthedocs.io/projects/astroid/en/latest/
GNU Lesser General Public License v2.1
535 stars 276 forks source link

Name lookup can lead to maximum recursion errors in certain situations #264

Open pylint-bot opened 9 years ago

pylint-bot commented 9 years ago

Originally reported by: Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore)


Given the following code, astroid will crash with a RuntimeError. The problem occurs because k is not inferred as the argument, but as the iterating element from the comprehension, which makes dict(**k) to be reevaluated at each inference step. This might be solved when we'll rewrite the lookup mechanism, since right now it's scattered all over the place.

#!python

from astroid.test_utils import extract_node
n = extract_node('''

def test(k):
   (k for k in __(dict(**k)))
''')
print(next(n.infer()))

brycepg commented 6 years ago

For the given example, what do you think about having the iter part of the Comprehension node ignore the GeneratorExp scope? That would fix the lookup and the iter (__(dict(**k))) part of the comprehension doesn't really have meaningful scope in the comprehension