[Python-checkins] No need to test "istep==1" twice. (GH-24064)
rhettinger
webhook-mailer at python.org
Sat Jan 2 15:10:00 EST 2021
https://github.com/python/cpython/commit/8f8de7380cd7fee4972a10240ad2b0fdc332b14d
commit: 8f8de7380cd7fee4972a10240ad2b0fdc332b14d
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2021-01-02T12:09:56-08:00
summary:
No need to test "istep==1" twice. (GH-24064)
files:
M Lib/random.py
diff --git a/Lib/random.py b/Lib/random.py
index 97495f0985e7d..4142e2e860c8c 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -351,9 +351,9 @@ def randrange(self, start, stop=None, step=_ONE):
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 @@ def randrange(self, start, stop=None, step=_ONE):
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):
More information about the Python-checkins
mailing list