Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def getitem(a, b):
def indexOf(a, b):
"Return the first index of b in a."
for i, j in enumerate(a):
if j == b:
if j is b or j == b:
return i
else:
raise ValueError('sequence.index(x): x not in sequence')
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ def test_indexOf(self):
self.assertRaises(ZeroDivisionError, operator.indexOf, BadIterable(), 1)
self.assertEqual(operator.indexOf([4, 3, 2, 1], 3), 1)
self.assertRaises(ValueError, operator.indexOf, [4, 3, 2, 1], 0)
nan = float("nan")
self.assertEqual(operator.indexOf([nan, nan, 21], nan), 0)
Comment on lines +191 to +192

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to add a test for {} as in #27007.

self.assertEqual(operator.indexOf([{}, 1, {}, 2], {}), 0)

def test_invert(self):
operator = self.module
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make the implementation consistency of :func:`~operator.indexOf` between
C and Python versions. Patch by Dong-hee Na.