Any other Python flaws?

Michael Hudson mwh at python.net
Mon Jun 18 18:28:50 EDT 2001


D-Man <dsh8290 at rit.edu> writes:

> On Mon, Jun 18, 2001 at 08:10:12PM +0100, Michael Hudson wrote:
> | D-Man <dsh8290 at rit.edu> writes:
> | 
> | > On Fri, Jun 15, 2001 at 02:18:04PM -0500, Michael Chermside wrote:
> | > | Oh well... at least people don't bump into this one much. And if you
> | > | accidently clobber it, you can restore things with:
> | > | 
> | > | def __None():
> | > |     pass
> | > | None = __None()
> | > 
> | > Well, that doesn't work.  One of the key features of 'None' is that
> | > there only ever exists a single instance.  This would create a new,
> | > unique, instance bound to (a more local) 'None'.
> | 
> | No it wouldn't.  Try it!
> 
> <slaps forehead after looking much closer>
> 
> Yeah, he used 'def', not 'class'!

I wondered if that was what you thought.

> | I agree that what Michael posted doesn't really do what he wanted; but
> | it doesn't do what you said, either.
> 
> It seems to, with some cursory tests in the interactive interpreter.

Yeah, it looks the same, but None is being found in the global
namespace, not the builtin one like normal.  I can't think of any
remotely sane situation where this would make a difference, but the
difference is there.  Eg. consider assigning to __builins__.None (I
don't recommend actually doing this!).

> I would have to look at the source to see _how_ the function
> implicitly returns 'None' to understand why it doesn't behave as
> intended.

Because falling off the end of a function compiles into a LOAD_CONST
instruction with an argument of Py_None and nothing you can do in
Python will affect the value of (the C symbol) Py_None.

Cheers,
M.

-- 
  Just getting something to work usually means writing reams of code
  fast, like a Stephen King novel, but making it maintainable and
  high-quality code that really expresses the ideas well, is like
  writing poetry.  Art is taking away.  -- Erik Naggum, comp.lang.lisp



More information about the Python-list mailing list