pylint-dev / pylint-dev/astroid
[2.0 bugs] Imported nodes in the builtins mock AST and builtin_lookup()
- Dominant language
- Python
- Stars
- 582
- Forks
- 357
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
Originally reported by: **BitBucket: [ceridwenv](http://bitbucket.org/ceridwenv), GitHub: @ceridwen**
---
I've already tweaked builtin_lookup() to accommodate cases where ast_from_object() is creating an AssignName node because of an alias to the same object in the builtins module. However, there's another issue that's less clear how to solve: in some cases, the builtins module has objects that actually belong to another module. The proximate test failure caused by this case is that on Python3, open() is imported from io:
``` python
FAIL: test_builtin_open (unittest_inference.InferenceTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "~/code/astroid/.tox/py34/lib/python3.4/site-packages/astroid/tests/unittest_inference.py", line 811, in test_builtin_open
self.assertIsInstance(inferred[0], nodes.FunctionDef)
AssertionError: Uninferable is not an instance of
```
However, there are other cases. ast_from_object() tries to create an AST that's as close as possible to the AST that would create the object if it were compiled. I think this should probably be solved in builtin_lookup(), but what's the best way to do it?
---
- Bitbucket: https://bitbucket.org/logilab/astroid/issue/261
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing test_builtin_open in astroid/tests/unittest_inference.py and trace how ast_from_object() represents builtins objects imported from another module. Then inspect builtin_lookup() and the existing alias handling. Done means the Python 3 open() case infers a nodes.FunctionDef and related imported-object cases are covered without regressing builtin aliases.
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
- 30/100