JLLeitschuh / bulk-security-pr-generator

Generate thousands of pull requests to fix widespread security vulnerabilities across GitHub.
MIT License
34 stars 14 forks source link

Replaces is operator with == for literal or new object comparisons #9

Closed pixeebot[bot] closed 9 months ago

pixeebot[bot] commented 9 months ago

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:

@pixeebot next

... and I will open a new PR right away!

Powered by: pixeebot (codemod ID: pixee:python/literal-or-new-object-identity)