[Python-bugs-list] [ python-Bugs-478534 ] SystemError with WeakKeyDictionary

noreply@sourceforge.net noreply@sourceforge.net
Mon, 05 Nov 2001 19:16:03 -0800


Bugs item #478534, was opened at 2001-11-05 19:15
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=478534&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Sverker Nilsson (svenil)
Assigned to: Nobody/Anonymous (nobody)
Summary: SystemError with WeakKeyDictionary

Initial Comment:
SystemError with WeakKeyDictionary

A SystemError is generated when trying
to iterate over a function returned from a
function that stored it in a WeakKeyDictionary.
The expected error was TypeError.

Sverker Nilsson

Examples:

This program gives a SystemError:

import weakref
ref = weakref.WeakKeyDictionary()

def encapsulate():
    f = lambda : ()
    ref[f] = None
    return f

for x in encapsulate():
 print x

Python 2.2b1 (#5, Oct 20 2001, 03:03:53) 
[GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/tmp/pythona04442", line 9, in ?
    for x in encapsulate():
SystemError: error return without exception set
>>> 

A variation of it, with a temporary variable,
gives the expected TypeError:

import weakref
ref = weakref.WeakKeyDictionary()

def encapsulate():
    f = lambda : ()
    ref[f] = None
    return f

g = encapsulate()
for x in g:
 print x


Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/tmp/pythona04442", line 10, in ?
    for x in g:
TypeError: iteration over non-sequence
>>>



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

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