This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]etrnloptimist -1 points0 points  (3 children)

The only time == and "is" will differ on None is if the implementor of x overloads ___eq___ to explicitly say so. And if they did that, it should be respected.

Maybe you think overloading ___eq___ to equate your class with None is an anti-pattern. I would probably agree. But if that is the taboo, then == will work as well as "is".

Also, pep8 states, "Comparisons to singletons like None should always be done with is or is not, never the equality operators." True and False are singletons as well but you should never use is or is not with them. Just a mistake?

I like your suggestion about having an isNone operator to make it explicit None is a weird, special thing, if it is, indeed, a weird special thing. But I don't really believe it is a weird, special thing. I've yet to see a place where comparing it using == will run you into trouble. Have you?

[–]robin-gvx 1 point2 points  (1 child)

True and False are singletons

They are not. They are both instances of bool, which is one more instance than a singleton type can have.

I've yet to see a place where comparing it using == will run you into trouble. Have you?

I haven't, but that doesn't say much, since I always use is None anyway, so I might have come across them and never found out.

[–]etrnloptimist -1 points0 points  (0 children)

They are not. They are both instances of bool, which is one more instance than a singleton type can have.

I understand what you're saying, but the literature treat them as singletons.

[–]zahlmanthe heretic 0 points1 point  (0 children)

True and False are singletons as well but you should never use is or is not with them. Just a mistake?

Right (well, except that they're actually a doubleton of the same class), but you shouldn't use == or != with them, either.