[Zope-dev] Making PersistentList satisfy zope.schema.List
Paul Carduner
paulcarduner at gmail.com
Tue Jun 30 15:17:31 EDT 2009
I noticed that PersistentList and PersistentDict do not satisfy
zope.schema.List or zope.schema.Dict, which is rather annoying. For
example:
class IBlogPost(Interface):
tags = zope.schema.List(title=u'Tags', value_type=zope.schema.TextLine)
class BlogPost(Persistent):
implements(IBlogPost)
tags = FieldProperty(IBlogPost['tags'])
def __init__(self):
super(BlogPost, self).__init__()
self.tags = persistent.list.PersistentList() #aaah, WrongType error...
will throw a WrongType: ([], <type 'list'>) error, which is especially
confusing because the repr for PersistentList makes it look an awful
lot like a regular list.
same thing happens with PersistentDict.
I would like to modify zope.schema._bootstrapfields by changing the
_type attribute of the List class to (list, UserList), and do the same
for Dict with (dict, UserDict). Then anything inheriting from
UserList (including PersistentList) will satisfy the schema.
Can anyone think of a reason why this would be bad?
--
Paul Carduner
http://www.carduner.net
More information about the Zope-Dev
mailing list