Attached Documents

patch : trying to fix this ticket (generator_attrs.diff)

patch : trying to fix this ticket (generator_attrs.diff)

Yet to do : at least test, modify __repr__ and __str__ for Generator

download
# HG changeset patch
# Parent bdc9ca4f5b0547f91a5c3b27ad65555bbeb0594f
support for generator attributes

diff -r bdc9ca4f5b05 bases.py
--- a/bases.py	Wed Oct 27 17:42:41 2010 +0200
+++ b/bases.py	Thu Oct 28 10:24:53 2010 +0200
@@ -280,7 +280,7 @@
         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
diff -r bdc9ca4f5b05 inference.py
--- a/inference.py	Wed Oct 27 17:42:41 2010 +0200
+++ b/inference.py	Thu Oct 28 10:24:53 2010 +0200
@@ -36,7 +36,7 @@
 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.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 -r bdc9ca4f5b05 test/unittest_lookup.py
--- a/test/unittest_lookup.py	Wed Oct 27 17:42:41 2010 +0200
+++ b/test/unittest_lookup.py	Thu Oct 28 10:24:53 2010 +0200
@@ -234,6 +234,18 @@
         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()
+iterer.next()
+        """)
+        next = tree.body[2].value.func
+        gener = next.expr.infered()[0]
+        # TODO : write tests
 
 
     def test_explicit___name__(self):