NoneType and new instances

Steven D'Aprano steve+comp.lang.python at
Fri Jul 29 03:29:39 CEST 2011

Chris Angelico wrote:

> On Fri, Jul 29, 2011 at 7:03 AM, Ethan Furman <ethan at> wrote:
>> 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?
> Why a lambda?
> def ThisFunctionWillReturnNone():
>     pass

This is a good use-case for a lambda. Ethan's use-case is a dict of

     fielddef = { 'empty':some_func, 'null':some_func }

There's no need to expose the constructor outside of the dict, hence:

     fielddef = { 'empty': str, 'null': lambda: None }

does the job. No need for a top-level named function.


More information about the Python-list mailing list