[Zope3-dev] bug setting value to None via edit form
Steve Alexander
steve@cat-box.net
Sun, 13 Jul 2003 10:27:48 +0300
> I think the approach you're taking is pretty esotheric. I'd like to see
> some use cases for making anything other than None a 'missing' value.
1: Text
In general, I want to consider an empty string to be "missing". The way
I generally write my Python classes that have variables that are strings
is to start with the strings initialized to '', not to None. In most
cases, '' is a more appropriate way to say "no value present" than using
None. The only time I'd want to use a value of None for something that
is usually a string is when '' is valid and meaningful data that has
been set for that string.
I'd like the Schema and Fields and Widgets to allow me to write Python
classes in the way that works for me, and not make me use None where I
would not normally use it.
2: Interface fields
Consider a field that represents a chosen interface. In the
zope.interface system, None means "the most general interface". Right
now, an Interface field cannot properly represent its special use of the
None value, and it cannot properly represent a "missing selection".
If I could define a special "missing value" for an Interface field, then
I could use None as a legitimate value, and be unambiguous about when no
value has been set.
> If a value is None, I'd say it's missing. If that's a legtimate value, then
> the field's not required.
If None is a legitimate value then the field is not required? I
disagree. If None is a legitimate value then it should be offered for
selection along with all the other legitimate values.
This should not interfere with whether or not a field is required.
That would be messy.
> Default values can be handled explicitly -- e.g.
> field.setDefaultValue(), or field.set(field.default). Personally, I
> cringe at this:
>
> def grok(alpha, beta, gamma=None):
> if gamma is None:
> gamma = 4711 # default value for gamma
>
> and would spell it:
>
> def grok(alpha, beta, gamma=4711):
> if grok is None:
> # maybe complain here?
It is very bad to do this when you have a mutable value there:
def grok(alpha, beta, gamma=[]):
if grok is None:
# maybe complain here?
It is too easy to accidentally use the value of gamma, and return it, or
store it, or mutate it.
> I.e. if I set something to None, I expect it to stay None, else raise an
> error...at least in the case of setting field values.
>
> I suspect we'll end up seeing field.missing_value = None in every case,
> with perhaps some very funky exceptions.
Of course field.missing_value will be None by default. As it will be the
default, you won't ever see it.
> I also suspect I stand to be corrected in a moment ;-)
Have I provided a convincing case?
--
Steve Alexander