A newbie question about class

Mark McEahern marklists at mceahern.com
Sun Feb 10 17:27:17 EST 2002


[Joshua Muskovitz]
> And yet, unless you do use things like "!= None", bugs in packages like
> FixedPoint would propogate.  It's a double edged sword.  Being able to use
> "is not None" is a good way to be able to work around a bug like this (if
> you don't have access to the source, for example), but I would hesitate to
> say that it is "better".

Hmm, here's why I think it's better.  (And I hope I'm not merely repeating
myself--or worse, contradicting myself!--if so, I apologize.)

If I use "is [not] None", I don't have to worry about it.

And to constrain my point, this again assumes that it's my code that's doing
the comparison.  I view the talk of better to be entirely contingent on what
the actual particular situation is, whether there's third party sources,
etc.

Is failing to compare to None a bug?  Maybe, maybe not.  If it's up to me,
I'd compare to None by identity.  Wouldn't you?

Of course, you may not know you're comparing to None:

	f = None
	doFoo(f)

	def doFoo(value):
		if value == g:
			...

In other words, what if None is on the left-hand side?  I guess all I can
say is that I consider that a different question.

I hope I've properly constrained and refined the sense in which I think it's
clearly better to compare to None by identity.

Cheers,

// mark





More information about the Python-list mailing list