Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10496

Re: NoneType and new instances

From Terry Reedy <tjreedy@udel.edu>
Subject Re: NoneType and new instances
Date 2011-07-28 21:32 -0400
References <4E3182C3.9040306@stoneleaf.us> <CALwzidmRwWqS-nY3==8XetBMe2cS7DRikZ6OWOwbQ61w99X9tg@mail.gmail.com> <4E31CE8F.4080606@stoneleaf.us>
Newsgroups comp.lang.python
Message-ID <mailman.1601.1311903154.1164.python-list@python.org> (permalink)

Show all headers | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: NoneType and new instances Terry Reedy <tjreedy@udel.edu> - 2011-07-28 21:32 -0400

csiph-web