Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10496 > unrolled thread
| Started by | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| First post | 2011-07-28 21:32 -0400 |
| Last post | 2011-07-28 21:32 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: NoneType and new instances Terry Reedy <tjreedy@udel.edu> - 2011-07-28 21:32 -0400
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2011-07-28 21:32 -0400 |
| Subject | Re: NoneType and new instances |
| Message-ID | <mailman.1601.1311903154.1164.python-list@python.org> |
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.
Back to top | Article view | comp.lang.python
csiph-web