For the given code
def greater(n):
if n > 3:
res = True
else:
res = False
return res
a = greater(5)
print(hex(id(a)))
print(hex(id(True)))
b = True
print(hex(id(b)))
if a == True:
print('yes')
else:
print('no')
pylint suggests pylint_example.py:16:4: C0121: Comparison 'a == True' should be 'a is True' if checking for the singleton value True, or 'a' if testing for truthiness (singleton-comparison)
a is True will check both address and value
and I cannot assume immutable variables will have the same address
Thus, changing a == True to a is True may lead to incorrect results (a and True may have different addresses in memory). Why does pylint suggest that?
Though
print(hex(id(a)))
print(hex(id(True)))
b = True
print(hex(id(b)))
part gives consistent results. I am not sure if that would work in general.