What's wrong with `is not None`?

F

Frans Englich

That's what PyChecker tells me, at least.

A line of:

if testReport is not None:

results in:

runner.py:587: Using is not None, may not always work

In what circumstances can `is not None` fail? How and why does it fail?

What is the equivalent expression which is more secure; `!= None`?


Cheers,

Frans
 
J

Jive Dadson

Frans said:
That's what PyChecker tells me, at least.

A line of:

if testReport is not None:

results in:

runner.py:587: Using is not None, may not always work

In what circumstances can `is not None` fail? How and why does it fail?

What is the equivalent expression which is more secure; `!= None`?

Yeah, that'll do it.

Incredibly, Microsoft has patented the "isnot" operator. I kid you not.
They are amassing an incredible number of patents, many with no more
merit than the "isnot" one. I'll leave it to your imagination as to
why.
 
S

Stefan Behnel

Frans said:
What is the equivalent expression which is more secure; `!= None`?

Note that this is not necessarily equivalent. '!=' and '==' possibly run
method calls on objects which can be costly depending on their
implementation and can even raise exceptions if called with None. If I
want to check for None, I always do it with "is". It's a constant after all...

Stefan
 
?

=?iso-8859-1?Q?Fran=E7ois?= Pinard

[Stefan Behnel]
If I want to check for None, I always do it with "is". It's a constant
after all...

So do I. There is only one None object, for which an `is' test is
especially appropriate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top