[Grok-dev] Re: Problems rendering zope.schema.List

Tres Seaver tseaver at palladion.com
Thu Jul 5 12:00:18 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Luciano Ramalho wrote:
> This is a gotcha that got me before... Philikon helped me: add a
> default argument to the list constructor, like this:
> 
>         creators = schema.List(title=u"Authors", required=False,
>                                value_type=schema.TextLine(), default=[])
> 
> The problem is that the list must never be None. When empty, it must be [].
> 
> IMHO, it's a usability bug in the Zope3 API. If the list fails
> miserably when it's None, then the default=[] should be automatic. Or
> is there some ratinonale for the way things are?


"Danger, Will Robinson!".  Mutable defaults are not going to produce
happy results, at least if the 'List' implementation mutates them.
List should be checking for None internally, and adding its own *new*
empty list if no value is passed (Python will recycle the one created by
the list literal across *all* uses).


Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGjRWS+gerLs4ltQ4RAmyfAKCVP7SKwLCnk0/1oJm/FNRHdK5rZACfRMRB
lEwBAln+3rusyYhPdOHoB6k=
=eJh0
-----END PGP SIGNATURE-----



More information about the Grok-dev mailing list