[Python-checkins] Minor code nit: Move an unrelated statement out of a try clause in Sequence.index (GH-32330)

rhettinger webhook-mailer at python.org
Wed Apr 6 14:03:41 EDT 2022


https://github.com/python/cpython/commit/59a99ae277e7d9f47edd4a538c1239d39f10db0c
commit: 59a99ae277e7d9f47edd4a538c1239d39f10db0c
branch: main
author: Géry Ogam <gery.ogam at gmail.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2022-04-06T13:03:36-05:00
summary:

Minor code nit: Move an unrelated statement out of a try clause in Sequence.index (GH-32330)

files:
M Lib/_collections_abc.py

diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py
index 86eb042e3a75a..e96e4c3535586 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -1022,10 +1022,10 @@ def index(self, value, start=0, stop=None):
         while stop is None or i < stop:
             try:
                 v = self[i]
-                if v is value or v == value:
-                    return i
             except IndexError:
                 break
+            if v is value or v == value:
+                return i
             i += 1
         raise ValueError
 



More information about the Python-checkins mailing list