[New-bugs-announce] [issue7170] subclasses of (some) built-in types are not weakref-able

Daniel Stutzbach report at bugs.python.org
Mon Oct 19 23:48:08 CEST 2009

New submission from Daniel Stutzbach <daniel at stutzbachenterprises.com>:

The documentation for weakref contains the following example:


Several built-in types such as list and dict do not directly support
weak references but can add support through subclassing:

class Dict(dict):

obj = Dict(red=1, green=2, blue=3)   # this object is weak referenceable

While this works fine for list and dict, it does not work for tuple or int:

>>> class Tuple(tuple):
...     pass
>>> obj = Tuple()
>>> weakref.ref(obj)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot create weak reference to 'Tuple' object

I've tried it in Python 2.5, 2.6, and 3.1.

components: Interpreter Core
messages: 94260
nosy: stutzbach
severity: normal
status: open
title: subclasses of (some) built-in types are not weakref-able
type: behavior
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.0, Python 3.1, Python 3.2

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list