Skip to content

Commit

Permalink
Added extra test and small tweak to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrecsilva committed Dec 21, 2023
1 parent 34b792f commit 4d87b31
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The `is` and `is not` operator will only return `True` when the expression have the same `id`, that is, `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.
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:

Expand Down
10 changes: 10 additions & 0 deletions tests/codemods/test_literal_or_new_object_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def test_list(self, tmpdir):
self.run_and_assert(tmpdir, dedent(input_code), dedent(expected))
assert len(self.file_context.codemod_changes) == 1

def test_list_lhs(self, tmpdir):
input_code = """\
[1,2,3] is l
"""
expected = """\
[1,2,3] == l
"""
self.run_and_assert(tmpdir, dedent(input_code), dedent(expected))
assert len(self.file_context.codemod_changes) == 1

def test_list_function(self, tmpdir):
input_code = """\
l is list({1,2,3})
Expand Down

0 comments on commit 4d87b31

Please sign in to comment.