[Python-bugs-list] [ python-Bugs-591704 ] generators can't be weakly referenced

noreply@sourceforge.net noreply@sourceforge.net
Fri, 09 Aug 2002 11:38:41 -0700


Bugs item #591704, was opened at 2002-08-06 15:10
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=591704&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2.1
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: H. Richard Harkins (hrharkins)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: generators can't be weakly referenced

Initial Comment:
I can't seem to weakly reference generators.  I can't
think of a good reason that this shouldn't work.  Here
is a code snippet to demonstrate the issue:

>>> from __future__ import generators
>>> import weakref
>>> def f():
...   yield "HELLO"
...
>>> weakref.proxy(f())
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: cannot create weak reference to 'generator'
object
>>>



----------------------------------------------------------------------

>Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2002-08-09 14:38

Message:
Logged In: YES 
user_id=3066

I don't see any reason a generator-iterator shouldn't be
weakly referencable.  Fixing this and making the resulting
proxy useful involved:

Adding iterator protocol support to weakref.proxy objects:
Objects/weakrefobject.c 1.10

Adding weakref support to generator-iterator objects:
Python/ceval.c 2.323

Adding tests:
Lib/test/test_generators.py 1.37

I'm not sure if this counts as a new feature or not; I'll
leave that up to whoever's thinking about Python 2.2.2 (not me).

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=591704&group_id=5470