On 7/28/2011 5:03 PM, Ethan Furman wrote:
I'm glad you asked! I'm using dictionaries to describe fields and
what their return values should be. There happen to be two special
cases: empty and Null. So a portion of the dictionary looks like:
fielddef = { 'empty':some_func, 'null':some_func }
Depending on the needs of the user, `some_func` might be `str`,
`int`, `custom_class`, or `NoneType`. Somewhere else in the code I
have:
if not value: # or some such cls = fielddef['empty'] return cls()
This works for *everything* except NoneType. g
~Ethan~
PS I'll use a lambda to get around it, but that's not very elegant.
Why shouldn't NoneType be able to return the singleton None?
Possibly historical accident. You could ask on python-ideas
or put a feature request on the tracker. Start with the first in case
there is a ready answer I do not know of.
The big question is whether there is code depending on current behavior.
--
http://mail.python.org/mailman/listinfo/python-list