Permanent objects?
Cliff Wells
clifford.wells at attbi.com
Thu Dec 26 01:02:24 EST 2002
On Wed, 2002-12-25 at 13:46, Erik Max Francis wrote:
> Kevin Altis wrote:
>
> > Hmm, I think I tend to use
> >
> > if x == None:
> > and
> > if x != None:
> >
> > rather than
> >
> > if x is None:
> > and
> > if not x is None:
> >
> > I don't suppose it really matters or that one is better or clearer
> > than the
> > other?
>
> If everybody plays together well, it shouldn't make a difference, but
> someone perverse could create a custom instance that overrides either
> __eq__ or __cmp__ so that tests equal to None. I can't think of a case
> when it would appropriate for someone to do this, but someone _could_.
But then isn't this sort of like the case where a function tests the
type of object being passed to it (i.e. type(s) == type(""))? There
have been arguments on this list in the past that it's bad to explicitly
test for a particular type, so wouldn't this fall in the same category?
That is, if an object mimics a particular type, and can be used in place
of that type, why should a function exclude it if it isn't that type?
For instance, if a function expects a file, but is passed a file-like
object, it shouldn't reject that object just because it isn't a real
file, doing so only limits the usefulness of the function. It seems
that by that argument, x == None would be preferable to x is None.
I'd be interested in hearing thoughts on this.
--
Cliff Wells <clifford.wells at attbi.com>
More information about the Python-list
mailing list