meta None?

Thomas Wouters thomas at xs4all.net
Mon Aug 21 04:16:29 EDT 2000


On Mon, Aug 21, 2000 at 12:57:01AM -0400, Tripp Lilley wrote:

> I'd like to implement a meta-None class... that is, a class that behaves
> like None regardless of what you subject it to:

*why* ?

> 	1: print metaNone		# displays 'None'
> 	2: print metaNone( )	# displays 'None'
> 
> 	3: if metaNone is None: print "yes"	# displays 'yes'
> 	4: if metaNone( ) is None: print "yes"	# displays 'yes'

> I understand how to get behaviours 1, 2, and 4 by overloading __repr__
> and __call__. How would I get behaviour 3? I haven't found anything in a
> cursory search of my literature suggesting I can overload "is".

You cannot. 'is' is not overloadable because it's the identity check: it
determines whether the left and right operand refer to the *same object*.
not something with a similar value. So, "don't do that then" is the answer.
Either use '==', or work around the problem entirely differently. If you
told us what you're trying to do, we might be able to help ;)

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list