None assigment

Gregoire Welraeds greg at perceval.be
Fri Feb 9 09:38:42 CET 2001


In reply to the message of Michael Hudson sent on Feb 8 (see below) :

~# What's going on?  frameobject.c:172 is what's going on:
~# 
~# 	if (builtins == NULL) {
~# 		/* No builtins!  Make up a minimal one. */
~# 		builtins = PyDict_New();
~# 		if (builtins == NULL || /* Give them 'None', at least. */
~# 		    PyDict_SetItemString(builtins, "None", Py_None) < 0) {
~# 			Py_DECREF(f);
~# 			return NULL;
~# 		}
~# 	}

So we guess that the None "object" (label, value, and so on :) is always
to a minimal builtin namespace because it is required to create a
"void" function (function that return nothing). And maybe there is a other
place in the python C code where None have to be defined. 

Maybe None have been added to builtin to avoid special cases. But it
becomes clear, as we understand it, that None is now a special case of
builtin. 

So, following that thought, we think that None should be a reserved word. 

Furthermore, None is some kind of magic value which have a special
conceptual meaning such as nil in other languages or the magic /dev/null
...

And we all agree that programmers should not touch to the value of
__builtin__.None. We think that the ability to override None because None
is a builtin is a conceptual problem.

Gregoire and Xavier
Perceval Development team, python division (and some other more :)
-------------------------------------------------------------------------------
Perceval Technologies sa/nv	Tel: +32-2-6409194		
Rue Tenbosch, 9			Fax: +32-2-6403154		
B-1000 Brussels			general information:   info at perceval.net
BELGIUM				technical information: helpdesk at perceval.net
URL: http://www.perceval.be/
-------------------------------------------------------------------------------

On 8 Feb 2001, Michael Hudson wrote:

~# Date: 08 Feb 2001 20:05:48 +0000
~# From: Michael Hudson <mwh21 at cam.ac.uk>
~# To: python-list at python.org
~# Newsgroups: comp.lang.python
~# Subject: Re: None assigment
~# 
~# "Rainer Deyke" <root at rainerdeyke.com> writes:
~# 
~# > "Simon Brunning" <SBrunning at trisystems.co.uk> wrote in message
~# > news:mailman.981653763.25307.python-list at python.org...
~# > > > From: Gregoire Welraeds [SMTP:greg at perceval.be]
~# > > > > After doing "None = 2", you can "del None" to get the default value
~# > > > > back.
~# > >
~# > > Hmm. This is true - I didn't know that.
~# > >
~# > > > If we follow that logic, I could use any non assigned variable to have
~# > the
~# > > > following working:
~# > > >
~# > > > >>> a= [1,'',3]
~# > > > >>> filter(b,a)
~# > > >
~# > > > but this won't work as the interpreter complains that there is no
~# > variable
~# > > > named b.
~# > >
~# > > You can't do this with *ordinary* labels - by del'ing them, you are
~# > > un-assigning them. But the 'None' label is *extraordinary*, obviously.
~# > 
~# > Actually, it's just in '__builtins__'.  When you assign to 'None', you
~# > create a variable in the module namespace which hides '__builtins__.None'.
~# > When you delete it, the 'None' in '__builtins__' is revealed.  This applies
~# > to all labels:
~# 
~# It's not very often I come up against something I don't understand
~# in Python, but try this:
~# 
~# >>> del __builtins__ 
~# 
~# This makes Python, erm, interesting, to use:
~# 
~# >>> import sys
~# Traceback (most recent call last):
~#   File "<stdin>", line 1, in ?
~# ImportError: __import__ not found
~# 
~# but yet:
~# 
~# >>> None 
~# >>> 
~# 
~# i.e. None still gets found.
~# 
~# What's going on?  frameobject.c:172 is what's going on:
~# 
~# 	if (builtins == NULL) {
~# 		/* No builtins!  Make up a minimal one. */
~# 		builtins = PyDict_New();
~# 		if (builtins == NULL || /* Give them 'None', at least. */
~# 		    PyDict_SetItemString(builtins, "None", Py_None) < 0) {
~# 			Py_DECREF(f);
~# 			return NULL;
~# 		}
~# 	}
~# 
~# Well, I though I'd share my little traipse through Python's innards
~# with you all...
~# 
~# Cheers,
~# M.
~# 
~# -- 
~#   Clue: You've got the appropriate amount of hostility for the
~#   Monastery, however you are metaphorically getting out of the 
~#   safari jeep and kicking the lions.                         -- coonec
~#                -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html
~# -- 
~# http://mail.python.org/mailman/listinfo/python-list
~# 





More information about the Python-list mailing list