-
-
Notifications
You must be signed in to change notification settings - Fork 306
Closed
Description
Steps to reproduce
Run following code:
import astroid
code = "def func(): pass"
funcdef = astroid.extract_node(code)
print(next(funcdef._infer()))
Current behavior
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-4-0a19b019c67b> in <module>
----> 1 print(next(funcdef._infer()))
/dat/uber/prod/python/venv/py_3.7.4_prod_20200604_0/lib/python3.7/site-packages/astroid/inference.py in _cached_generator(func, instance, args, kwargs, _cache)
957 @wrapt.decorator
958 def _cached_generator(func, instance, args, kwargs, _cache={}):
--> 959 node = args[0]
960 try:
961 return iter(_cache[func, id(node)])
IndexError: tuple index out of range
This is actually a combination of two bugs:
astroid.inference._cached_generatoris decorated bywrapt.decorator. And in the mean time you try to access node instance vianode = args[0]. This is incorrect, you should usenode = instanceinstead.NodeNG.infercalls_inferwithcontextas positional argument instead of keyword one. See https://github.com/PyCQA/astroid/blob/master/astroid/node_classes.py#L363 and https://github.com/PyCQA/astroid/blob/master/astroid/node_classes.py#L371. That's why this error never happens in usual workflow.
Since _cached_generator works not as expected, this may also have some impact on inference caching, but I did not encounter any other issues here.
Expected behavior
No error
python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output
2.4.1