[pypy-svn] r78730 - in pypy/branch/fast-forward/pypy/interpreter: . test
afa at codespeak.net
afa at codespeak.net
Fri Nov 5 13:13:26 CET 2010
Author: afa
Date: Fri Nov 5 13:13:21 2010
New Revision: 78730
Modified:
pypy/branch/fast-forward/pypy/interpreter/generator.py
pypy/branch/fast-forward/pypy/interpreter/test/test_generator.py
pypy/branch/fast-forward/pypy/interpreter/typedef.py
Log:
Add gi_code and __name__ to generator objects
Modified: pypy/branch/fast-forward/pypy/interpreter/generator.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/generator.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/generator.py Fri Nov 5 13:13:21 2010
@@ -101,7 +101,7 @@
return self.send_ex(space.w_None, operr)
def descr_next(self):
- """next() -> the next value, or raise StopIteration"""
+ """x.next() -> the next value, or raise StopIteration"""
return self.send_ex(self.space.w_None)
def descr_close(self):
@@ -126,6 +126,13 @@
else:
return space.w_None
+ def descr_gi_code(space, self):
+ return self.frame.pycode
+
+ def descr__name__(space, self):
+ code_name = self.frame.pycode.co_name
+ return space.wrap(code_name)
+
def descr__del__(self):
"""
applevel __del__, which is called at a safe point after the
Modified: pypy/branch/fast-forward/pypy/interpreter/test/test_generator.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/test/test_generator.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/test/test_generator.py Fri Nov 5 13:13:21 2010
@@ -5,6 +5,14 @@
yield 1
assert f().next() == 1
+ def test_attributes(self):
+ def f():
+ yield 1
+ g = f()
+ assert g.gi_code is f.func_code
+ assert g.__name__ == 'f'
+ assert g.gi_frame is not None
+
def test_generator2(self):
def f():
yield 1
Modified: pypy/branch/fast-forward/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/typedef.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/typedef.py Fri Nov 5 13:13:21 2010
@@ -903,6 +903,8 @@
descrmismatch='__del__'),
gi_running = interp_attrproperty('running', cls=GeneratorIterator),
gi_frame = GetSetProperty(GeneratorIterator.descr_gi_frame),
+ gi_code = GetSetProperty(GeneratorIterator.descr_gi_code),
+ __name__ = GetSetProperty(GeneratorIterator.descr__name__),
__weakref__ = make_weakref_descr(GeneratorIterator),
)
GeneratorIterator.typedef.acceptable_as_base_class = False
More information about the Pypy-commit
mailing list