]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
No need to test "istep==1" twice. (GH-24064)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Sat, 2 Jan 2021 20:09:56 +0000 (12:09 -0800)
committerGitHub <noreply@github.com>
Sat, 2 Jan 2021 20:09:56 +0000 (12:09 -0800)
Lib/random.py

index 97495f0985e7d502dcaeb1e8f1c091476b4c0faf..4142e2e860c8c58576653ac96ac1aef368ba7c33 100644 (file)
@@ -351,9 +351,9 @@ class Random(_random.Random):
                       DeprecationWarning, 2)
                 raise ValueError("non-integer step for randrange()")
         width = istop - istart
-        if istep == 1 and width > 0:
-            return istart + self._randbelow(width)
         if istep == 1:
+            if width > 0:
+                return istart + self._randbelow(width)
             raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
 
         # Non-unit step argument supplied.
@@ -363,10 +363,8 @@ class Random(_random.Random):
             n = (width + istep + 1) // istep
         else:
             raise ValueError("zero step for randrange()")
-
         if n <= 0:
             raise ValueError("empty range for randrange()")
-
         return istart + istep * self._randbelow(n)
 
     def randint(self, a, b):