summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bases.py7
-rw-r--r--inference.py3
-rw-r--r--test/unittest_lookup.py14
3 files changed, 21 insertions, 3 deletions
diff --git a/bases.py b/bases.py
index c99eaa4a..a908b8a9 100644
--- a/bases.py
+++ b/bases.py
@@ -280,7 +280,7 @@ class BoundMethod(UnboundMethod):
return self._proxied.infer_call_result(caller, context)
-class Generator(Proxy):
+class Generator(Instance):
"""a special node representing a generator"""
def callable(self):
return True
@@ -291,6 +291,11 @@ class Generator(Proxy):
def display_type(self):
return 'Generator'
+ def __repr__(self):
+ return '<Generator(%s) l.%s at 0x%s>' % (self._proxied.name, self.lineno, id(self))
+
+ def __str__(self):
+ return 'Generator(%s)' % (self._proxied.name)
# decorators ##################################################################
diff --git a/inference.py b/inference.py
index 25c5fed5..597d450a 100644
--- a/inference.py
+++ b/inference.py
@@ -36,7 +36,7 @@ from logilab.astng import nodes, raw_building
from logilab.astng.manager import ASTNGManager
from logilab.astng import ASTNGError, InferenceError, UnresolvableName, \
NoDefault, NotFoundError, ASTNGBuildingException
-from logilab.astng.bases import YES, Instance, InferenceContext, \
+from logilab.astng.bases import YES, Instance, InferenceContext, Generator, \
_infer_stmts, copy_context, path_wrapper, raise_if_nothing_infered
from logilab.astng.protocols import _arguments_infer_argname
@@ -72,6 +72,7 @@ nodes.Const.pytype = Const_pytype
nodes.List._proxied = MANAGER.astng_from_class(list)
nodes.Tuple._proxied = MANAGER.astng_from_class(tuple)
nodes.Dict._proxied = MANAGER.astng_from_class(dict)
+Generator._proxied = MANAGER.infer_astng_from_something(type(a for a in ()))
class CallContext:
diff --git a/test/unittest_lookup.py b/test/unittest_lookup.py
index e0d66904..091cce03 100644
--- a/test/unittest_lookup.py
+++ b/test/unittest_lookup.py
@@ -232,7 +232,19 @@ var
var = astng.body[1].value
self.assertRaises(UnresolvableName, var.infered)
-
+ def test_generator_attributes(self):
+ tree = builder.string_build("""
+def count():
+ "ntesxt"
+ yield 0
+
+iterer = count()
+num = iterer.next()
+ """)
+ next = tree.body[2].value.func # Getattr
+ gener = next.expr.infered()[0] # Genrator
+ # TODO : this is because we dont support function attributes:
+ self.assertRaises(AttributeError, gener.getattr, 'next')
def test_explicit___name__(self):
code = '''