pylint-dev / pylint-dev/astroid
Inference contexts can't be reused
- Dominant language
- Python
- Stars
- 583
- Forks
- 357
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
Originally reported by: **Claudiu Popa (BitBucket: [PCManticore](http://bitbucket.org/PCManticore), GitHub: @PCManticore)**
---
Testing with the following code:
```
#!python
m = extract_node('...')
c = InferenceContext()
f = next(m['_tags'].infer(c))
f = next(m['_tags'].infer(c))
```
The last `.infer()` call will result in a StopIteration, because when doing `context.push`,
the name `_tags` is already there. Instead, the wanted behaviour would be to retrieve the already inferred result from context.inferred and return it instead (this means that the context is not used internally, since the first one already has `_tags` inside `context.inferred`)
---
- Bitbucket: https://bitbucket.org/logilab/astroid/issue/108
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the InferenceContext and infer calls shown in the reproducer, then trace how context.push and context.inferred handle the existing _tags name. Confirm the fix by running the reproducer twice with the same context and verifying that the second infer call returns the already inferred result instead of raising StopIteration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100