[Python-checkins] Remove unnecessary and over-restrictive type check (GH-10905)

Raymond Hettinger webhook-mailer at python.org
Tue Dec 4 17:53:18 EST 2018


https://github.com/python/cpython/commit/09473ac0636c16c0ee96c4caf59f3da8ba8b4a57
commit: 09473ac0636c16c0ee96c4caf59f3da8ba8b4a57
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-12-04T14:53:14-08:00
summary:

Remove unnecessary and over-restrictive type check (GH-10905)

files:
M Lib/random.py

diff --git a/Lib/random.py b/Lib/random.py
index a7a86070c0a9..03c058a39d6e 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -718,8 +718,6 @@ def getrandbits(self, k):
         """getrandbits(k) -> x.  Generates an int with k random bits."""
         if k <= 0:
             raise ValueError('number of bits must be greater than zero')
-        if k != int(k):
-            raise TypeError('number of bits should be an integer')
         numbytes = (k + 7) // 8                       # bits / 8 and rounded up
         x = int.from_bytes(_urandom(numbytes), 'big')
         return x >> (numbytes * 8 - k)                # trim excess bits



More information about the Python-checkins mailing list