]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44558: Make the implementation consistency of operator.indexOf (GH-27012)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 5 Jul 2021 09:52:04 +0000 (02:52 -0700)
committerGitHub <noreply@github.com>
Mon, 5 Jul 2021 09:52:04 +0000 (02:52 -0700)
(cherry picked from commit 09302405d22e86884d6058226790c0cdf5b72f14)

Co-authored-by: Dong-hee Na <donghee.na@python.org>
Lib/operator.py
Lib/test/test_operator.py
Misc/NEWS.d/next/Library/2021-07-04-21-16-53.bpo-44558.cm7Slv.rst [new file with mode: 0644]

index fb58851fa6ef6732de021740cf16f79c51bb85a2..6782703476edee4d3b0605efc3e47db834d5f6c9 100644 (file)
@@ -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')
index 29f5e4275c55eb0fb130b8f42c4341a23d7b55fe..3093a7d8f7ec33a4b7c50b580c897486b8ffaca1 100644 (file)
@@ -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
diff --git a/Misc/NEWS.d/next/Library/2021-07-04-21-16-53.bpo-44558.cm7Slv.rst b/Misc/NEWS.d/next/Library/2021-07-04-21-16-53.bpo-44558.cm7Slv.rst
new file mode 100644 (file)
index 0000000..647a704
--- /dev/null
@@ -0,0 +1,2 @@
+Make the implementation consistency of :func:`~operator.indexOf` between
+C and Python versions. Patch by Dong-hee Na.