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


Groups > comp.lang.python > #10496

Re: NoneType and new instances

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'behavior.': 0.07; 'skip:` 10': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'value:': 0.09; '~ethan~': 0.09; 'wrote:': 0.15; 'dictionaries': 0.16; 'lambda': 0.16; 'null.': 0.16; 'pm,': 0.16; 'possibly': 0.16; 'have:': 0.19; 'of.': 0.19; 'header:In-Reply-To:1': 0.22; 'dictionary': 0.23; "shouldn't": 0.23; 'somewhere': 0.23; 'code': 0.24; "i'm": 0.27; 'looks': 0.30; 'values': 0.31; "skip:' 10": 0.32; "i'll": 0.33; 'to:addr:python-list': 0.34; 'header:X -Complaints-To:1': 0.34; 'header:User-Agent:1': 0.34; 'there': 0.34; 'be.': 0.34; 'describe': 0.34; 'like:': 0.35; 'question': 0.35; 'subject:new': 0.36; 'some': 0.37; 'but': 0.37; 'could': 0.37; 'using': 0.37; 'received:org': 0.38; 'subject:: ': 0.38; 'portion': 0.38; 'else': 0.38; 'two': 0.38; 'put': 0.38; 'case': 0.39; 'should': 0.39; 'header:Mime-Version:1': 0.39; 'except': 0.39; 'to:addr:python.org': 0.39; 'might': 0.39; 'happen': 0.62; 'ready': 0.64; 'special': 0.67; 'glad': 0.71; 'historical': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: NoneType and new instances
Date Thu, 28 Jul 2011 21:32:34 -0400
References <4E3182C3.9040306@stoneleaf.us> <CALwzidmRwWqS-nY3==8XetBMe2cS7DRikZ6OWOwbQ61w99X9tg@mail.gmail.com> <4E31CE8F.4080606@stoneleaf.us>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 206.205.249.126
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20110624 Thunderbird/5.0
In-Reply-To <4E31CE8F.4080606@stoneleaf.us>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1601.1311903154.1164.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1311903154 news.xs4all.nl 23913 [2001:888:2000:d::a6]:54168
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10496

Show key headers only | 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