[Patches] UserDict/UserList: raise TypeError when trying to set attrs

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Mon, 14 Feb 2000 18:03:57 +0100


> I added a __setattr__ to UserDict and UserList. When trying to set
> attributes to dictionairies and lists, an error is raised.

import UserList

class MyList(UserList.UserList):
    def __init__(self):
        UserList.UserList.__init__(self)
        self.mydata =3D []

list =3D MyList()

Traceback (innermost last):
  File "bzzt.py", line 8, in ?
  File "bzzt.py", line 6, in __init__
  File "UserList.py", line 14, in __setattr__
    raise TypeError("object has read-only attributes")
TypeError: object has read-only attributes

</F>