__iadd__ and fellows missing (Python 2.2)
Mike C. Fletcher
mcfletch at rogers.com
Sat Apr 13 14:39:14 EDT 2002
I was unaware that there was no guarantee for 0-length tuples always
being unique objects. There are lots of places in my code where I use
0-length tuples in this pattern:
NULL = ()
class A:
def b( self, object=NULL ):
if object is NULL:
#was not specified
elif object is None:
#specified to be object None
Of course, I can use:
NULL = []
But I'd always avoided that because of bad associations with having
mutable objects as default parameters (yes, it doesn't actually matter
in this pattern, but it's a thirty-times-burned-thirty-first-shy thing).
Suppose I'll wind up using singleton instances instead.
Sigh. Will need to poke through every package I own and update them
someday.
Have fun,
Mike
Tim Peters wrote:
...
> The implementation can choose, or choose not, to share memory blobs for any
> value of an immutable type, and exactly when & which objects get shared can
> (and does) vary across releases. The only objects guaranteed to be
> singletons (meaning you'll always get exactly the same object no matter how
> its value is computed) are None, type objects (things the type() function
> returns), and in 2.3 True and False. So, in particular, "is" should never
> be used as a test for integer equality, or equality with an empty tuple or
> string.
...
More information about the Python-list
mailing list