The is and is not operator will only return True when the expression have the same id. In other words, a is b is equivalent to id(a) == id(b). New objects and literals have their own identities and thus shouldn't be compared with using the is or is not operators.
Our changes look something like this:
def foo(l):
- return l is [1,2,3]
+ return l == [1,2,3]
More reading
* [https://docs.python.org/3/library/stdtypes.html#comparisons](https://docs.python.org/3/library/stdtypes.html#comparisons)
I have additional improvements ready for this repo! If you want to see them, leave the comment:
The
is
andis not
operator will only returnTrue
when the expression have the sameid
. In other words,a is b
is equivalent toid(a) == id(b)
. New objects and literals have their own identities and thus shouldn't be compared with using theis
oris not
operators.Our changes look something like this:
More reading
* [https://docs.python.org/3/library/stdtypes.html#comparisons](https://docs.python.org/3/library/stdtypes.html#comparisons)I have additional improvements ready for this repo! If you want to see them, leave the comment:
... and I will open a new PR right away!
Powered by: pixeebot (codemod ID: pixee:python/literal-or-new-object-identity)