pep 336: Make None Callable

Michael J. Fromberger Michael.J.Fromberger at Clothing.Dartmouth.EDU
Thu Nov 4 09:05:16 EST 2004


In article <S-6dncb1OqobIRTcRVn-jw at comcast.com>,
 The Eternal Squire <eternalsquire at comcast.net> wrote:

> Terry Reedy wrote:
> 
>  >> PEP: 336
>  >> Abstract
>  >>
>  >>    None should be a callable object that when called with any
>  >>    arguments has no side effect and returns None.
>  >
>> Please no.  The None object, by definition, is an object with no 
>> value, no behavior (except compares), and no specific attributes 
>> (other than those common to all descendents of object).
> 
> I always saw None not as an object without value, but as the 
> universal false or ground symbol, similar to NIL in Lisp.

To indicate falsehood, Python already has its own "False" object, which 
is much preferable, in my view, to using None for that purpose.  Adding 
functionality to None (or to False, for that matter) just to serve a 
weak standard of convenience would be foolish.

> But isn't the point of Pythonic style to write something as tersely 
> elegant as possible?

Elegant, yes, but not necessarily terse.  If you really want terse, you 
might try programming in Perl, which has punctuation overloading for 
that very purpose.  A measure of elegance may be achieved by writing a 
shorter program, but that is not, by far, the only measure, nor is it 
the most important in my view.

> I'd rather not see a bunch of null methods sprinkled thru the classes 
> in the libraries that I have to write, and I'd rather not to have to 
> import it either.

It sounds, then (as Terry Reedy said), as if your PEP should include a 
proposal for a different sort of built-in object, such as this:

  class NilClass (object):
    def __init__(self):
      pass
    
    def __call__(self, *args, **kwargs):
      return self
    
    def __nonzero__(self):
      return False
    
    def __repr__(self):
      return "Nil"

  Nil = NilClass()

I still think this is a silly idea, but at least it doesn't track mud 
all over Python's nice clean rugs.

Cheers,
-M

-- 
Michael J. Fromberger             | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/  | Dartmouth College, Hanover, NH, USA



More information about the Python-list mailing list