From b9da2e288c2b3dab4588a5b2fe7f1ca742ace85b Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Sun, 4 Jul 2021 21:16:57 +0900 Subject: [PATCH 1/2] bpo-44558: Make the implementation consistency of operator.indexOf --- Lib/operator.py | 2 +- Lib/test/test_operator.py | 2 ++ .../next/Library/2021-07-04-21-16-53.bpo-44558.cm7Slv.rst | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2021-07-04-21-16-53.bpo-44558.cm7Slv.rst diff --git a/Lib/operator.py b/Lib/operator.py index fb58851fa6ef67..6782703476edee 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 1ecae85f62f2c9..3bde686ab52d65 100644 --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -188,6 +188,8 @@ 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) 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 00000000000000..647a70490d1bac --- /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. From 5e9690c2020b5024d81280dd4875ad9e3bf90a12 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Mon, 5 Jul 2021 16:39:50 +0900 Subject: [PATCH 2/2] bpo-44558 Add test case --- Lib/test/test_operator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py index 3bde686ab52d65..d50306b7f1ecb8 100644 --- a/Lib/test/test_operator.py +++ b/Lib/test/test_operator.py @@ -190,6 +190,7 @@ def test_indexOf(self): 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