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

Luciano Ramalho luciano at ramalho.org
Tue Jul 17 14:06:56 EDT 2007


On 7/5/07, Tres Seaver <tseaver at palladion.com> wrote:
> "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).

Thanks for the warning, Tres!

I am aware of the pitfalls of using mutable values in default args.
However, because the solution I mentioned was suggested by Philipp, I
assumed it was safe to do it in that particular case (setting an empty
list as default value for a List field to prevent an auto-generated
add form from choking while iterating over None).

I've spent some time since then trying to find "proper" way to solve
this. For example, I tried using an empty tuple instead of a list, but
I got "WrongType: ((), <type 'list'>)" (I hope the javaification of
Python in Zope 3 doesn't go much further).

It seems the only way to really solve this is patching the
implementation of the Zope 3 list field itself. But I am amazed this
has never bitten anyone before Sebastian and me. What am I missing?

Cheers,

Luciano


More information about the Grok-dev mailing list