pylint-bot / test

0 stars 0 forks source link

[2.0 bugs] Imported nodes in the builtins mock AST and builtin_lookup() #261

Open pylint-bot opened 8 years ago

pylint-bot commented 8 years ago

Originally reported by: BitBucket: 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:

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 <class 'astroid.tree.scoped_nodes.FunctionDef'>

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?


pylint-bot commented 8 years ago

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore?):


I don't think this needs to be fixed in builtin_lookup, it should do only lookup and fail if it's not possible to do so. Any other use case should belong somewhere else.

Without taking a close look at the problem, maybe this is related with _io / io discrepancy that the previous code hardcoded? https://bitbucket.org/logilab/astroid/src/473f94bc7afddb40295c6225861512e9485fbd3e/astroid/raw_building.py?at=default&fileviewer=file-view-default#raw_building.py-44