summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--_exceptions.py6
-rw-r--r--inference.py4
-rw-r--r--test/unittest_inference.py26
3 files changed, 31 insertions, 5 deletions
diff --git a/_exceptions.py b/_exceptions.py
index 8e2ee582..009f10ba 100644
--- a/_exceptions.py
+++ b/_exceptions.py
@@ -12,15 +12,13 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""this module contains exceptions used in the astng library
-:version: $Revision: 1.4 $
:author: Sylvain Thenault
-:copyright: 2003-2006 LOGILAB S.A. (Paris, FRANCE)
+:copyright: 2003-2007 LOGILAB S.A. (Paris, FRANCE)
:contact: http://www.logilab.fr/ -- mailto:python-projects@logilab.org
-:copyright: 2003-2006 Sylvain Thenault
+:copyright: 2003-2007 Sylvain Thenault
:contact: mailto:thenault@gmail.com
"""
-__revision__ = "$Id: _exceptions.py,v 1.4 2006-03-06 08:57:52 syt Exp $"
__doctype__ = "restructuredtext en"
class ASTNGError(Exception):
diff --git a/inference.py b/inference.py
index 9ec03485..68874550 100644
--- a/inference.py
+++ b/inference.py
@@ -345,10 +345,12 @@ def infer_from(self, context=None, asname=True):
name = context.lookupname
if name is None:
raise InferenceError()
- module = _imported_module_astng(self, self.modname)
if asname:
name = self.real_name(name)
+ module = _imported_module_astng(self, self.modname)
try:
+ context = copy_context(context)
+ context.lookupname = name
return _infer_stmts(module.getattr(name), context)
except NotFoundError:
raise InferenceError(name)
diff --git a/test/unittest_inference.py b/test/unittest_inference.py
index 9601231e..98edff32 100644
--- a/test/unittest_inference.py
+++ b/test/unittest_inference.py
@@ -741,6 +741,32 @@ x = randint(1)
value = [str(v) for v in infered]
self.assertEquals(value, ['Instance of %s.myarray' % __name__,
'Instance of __builtin__.int'])
+
+
+ def test_import_as(self):
+ data = '''
+import os.path as osp
+print osp.dirname(__file__)
+
+from os.path import exists as e
+assert e(__file__)
+
+from new import code as make_code
+print make_code
+ '''
+ astng = builder.string_build(data, __name__, __file__)
+ infered = list(astng.igetattr('osp'))
+ self.failUnlessEqual(len(infered), 1)
+ self.assertIsInstance(infered[0], nodes.Module)
+ self.failUnlessEqual(infered[0].name, 'os.path')
+ infered = list(astng.igetattr('e'))
+ self.failUnlessEqual(len(infered), 1)
+ self.assertIsInstance(infered[0], nodes.Function)
+ self.failUnlessEqual(infered[0].name, 'exists')
+ infered = list(astng.igetattr('make_code'))
+ self.failUnlessEqual(len(infered), 1)
+ self.assertIsInstance(infered[0], Instance)
+ self.failUnlessEqual(str(infered[0]), 'Instance of __builtin__.type')
if __name__ == '__main__':
from logilab.common.testlib import unittest_main