merge
diff --git a/Lib/random.py b/Lib/random.py
index 4ebc757..3fac699 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -220,10 +220,11 @@
Method=_MethodType, BuiltinMethod=_BuiltinMethodType):
"Return a random int in the range [0,n). Raises ValueError if n==0."
+ random = self.random
getrandbits = self.getrandbits
# Only call self.getrandbits if the original random() builtin method
# has not been overridden or if a new getrandbits() was supplied.
- if type(self.random) is BuiltinMethod or type(getrandbits) is Method:
+ if type(random) is BuiltinMethod or type(getrandbits) is Method:
k = n.bit_length() # don't use (n-1) here because n can be 1
r = getrandbits(k) # 0 <= r < 2**k
while r >= n:
@@ -231,7 +232,6 @@
return r
# There's an overriden random() method but no new getrandbits() method,
# so we can only use random() from here.
- random = self.random
if n >= maxsize:
_warn("Underlying random() generator does not supply \n"
"enough bits to choose from a population range this large.\n"
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index ade6ee7..56e8120 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -1080,8 +1080,10 @@
# test fidelity to the pure python version
c = CounterSubclassWithSetItem('abracadabra')
self.assertTrue(c.called)
+ self.assertEqual(dict(c), {'a': 5, 'b': 2, 'c': 1, 'd': 1, 'r':2 })
c = CounterSubclassWithGet('abracadabra')
self.assertTrue(c.called)
+ self.assertEqual(dict(c), {'a': 5, 'b': 2, 'c': 1, 'd': 1, 'r':2 })
################################################################################