mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
bpo-44558: Make the implementation consistency of operator.indexOf (GH-27012)
(cherry picked from commit 09302405d2
)
Co-authored-by: Dong-hee Na <donghee.na@python.org>
This commit is contained in:
parent
fe847a6285
commit
9f47d872db
3 changed files with 6 additions and 1 deletions
|
@ -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')
|
||||
|
|
|
@ -184,6 +184,9 @@ class OperatorTestCase:
|
|||
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)
|
||||
self.assertEqual(operator.indexOf([{}, 1, {}, 2], {}), 0)
|
||||
|
||||
def test_invert(self):
|
||||
operator = self.module
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Make the implementation consistency of :func:`~operator.indexOf` between
|
||||
C and Python versions. Patch by Dong-hee Na.
|
Loading…
Add table
Add a link
Reference in a new issue