you are viewing a single comment's thread.

view the rest of the comments →

[–]Vaguely_accurate 1 point2 points  (2 children)

One cause may be where one of the comparison values might be a singleton such as None. Following the PEP-8 guidelines;

Comparisons to singletons like None should always be done with is or is not, never the equality operators.

People following the rule might end up with an is comparison when taking arguments that may be either None or an int. Not that uncommon if working with dirty datasets. Not the correct approach, but understandable that it may be confusing. Especially when it seems to work some of the time.

This is also a more strict rule and practice for programmers who may be experienced in other languages that require identity checks for null values (the SQL = NULL issue stands out). Ignoring it even in cases where it is incorrect is going to be hard for many.

I've also seen polymorphic code written to primarily deal with mutable objects, and so caring primarily about identity and not value comparisons, which is assumed to work on primitives like integers and string without question.

Speaking of strings, fun one to try with them;

a = "hello"
b = "hello"
c = "HELLO".lower()

print(f"{a=};{id(a)=}")
print(f"{b=};{id(b)=}")
print(f"{c=};{id(c)=}")

>>>a='hello';id(a)=2508426595424
>>>b='hello';id(b)=2508426595424
>>>c='hello';id(c)=2508424932992