Consider this code snippet:
my_string = 'asdf'
print(my_string is 'xfje') #R0123
Pylint returns a recommendation R0123
on the second line, which I was unable to find on the error message wiki. There is a mention of it in this part of the docs, though:
literal-comparison (R0123):
Comparison to literal Used when comparing an object to a literal, which is usually what you do not want to do, since you can compare to a different literal than what was expected altogether.
This explanation is not helpful at all to me. I know that using is
for comparison between two string objects may lead to different results than expected, but for comparison of object to literal, it is identical to ==
. And when using ==
, the error disappears.
Why should I not use is
here?