[Python-checkins] bpo-44558: Make the implementation consistency of operator.indexOf (GH-27012)

corona10 webhook-mailer at python.org
Mon Jul 5 05:04:41 EDT 2021


https://github.com/python/cpython/commit/09302405d22e86884d6058226790c0cdf5b72f14
commit: 09302405d22e86884d6058226790c0cdf5b72f14
branch: main
author: Dong-hee Na <donghee.na at python.org>
committer: corona10 <donghee.na92 at gmail.com>
date: 2021-07-05T18:04:36+09:00
summary:

bpo-44558: Make the implementation consistency of operator.indexOf (GH-27012)

files:
A Misc/NEWS.d/next/Library/2021-07-04-21-16-53.bpo-44558.cm7Slv.rst
M Lib/operator.py
M Lib/test/test_operator.py

diff --git a/Lib/operator.py b/Lib/operator.py
index fb58851fa6ef6..6782703476ede 100644
--- a/Lib/operator.py
+++ b/Lib/operator.py
@@ -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')
diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py
index 1ecae85f62f2c..d50306b7f1ecb 100644
--- a/Lib/test/test_operator.py
+++ b/Lib/test/test_operator.py
@@ -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)
+        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
index 0000000000000..647a70490d1ba
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-07-04-21-16-53.bpo-44558.cm7Slv.rst
@@ -0,0 +1,2 @@
+Make the implementation consistency of :func:`~operator.indexOf` between
+C and Python versions. Patch by Dong-hee Na.



More information about the Python-checkins mailing list