pylint-dev / pylint-dev/astroid
Behavior of infer when function name clashes with brain
- Dominant language
- Python
- Stars
- 582
- Forks
- 357
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
Sorry if this is a dumb question. I have the following code:
```python
import astroid
node = astroid.extract_node(
"""
def sample(a, b=None):
return a
sample([1, 2, 5, 6], 2) #@
"""
)
inferred = next(node.infer())
elems = sorted(elem.value for elem in inferred.elts)
```
After inferring the return value to the `sample` call, the `elems` returned a list that contained 2 values, whereas it should be `[1, 2, 5, 6]` in this case. I understand that probably [random brain](https://github.com/PyCQA/astroid/tree/master/astroid/brain) has something to do with it, but why this behavior is the default even though `random` module was never imported?
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the behavior with the supplied astroid.extract_node snippet and compare the inferred result with the expected list. Then inspect how astroid.brain handles the random-related inference when no random import exists. Done means the behavior is explained and inference no longer selects the conflicting interpretation without an import, with a regression test covering the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100