https://github.com/python/cpython/commit/5ae669fc4e674968529cc32f7f31d14dddd76607
commit: 5ae669fc4e674968529cc32f7f31d14dddd76607
branch: main
author: Serhiy Storchaka <storch...@gmail.com>
committer: gpshead <g...@krypto.org>
date: 2025-06-10T18:51:08-07:00
summary:

gh-135326: Test support of __index__ in random.getrandbits() (#135356)

files:
M Lib/test/test_random.py

diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index 54910cd8054a1f..31ebcb3b8b0b00 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -14,6 +14,15 @@
 from fractions import Fraction
 from collections import abc, Counter
 
+
+class MyIndex:
+    def __init__(self, value):
+        self.value = value
+
+    def __index__(self):
+        return self.value
+
+
 class TestBasicOps:
     # Superclass with tests common to all generators.
     # Subclasses must arrange for self.gen to retrieve the Random instance
@@ -809,6 +818,9 @@ def test_getrandbits(self):
         self.gen.seed(1234567)
         self.assertEqual(self.gen.getrandbits(100),
                          97904845777343510404718956115)
+        self.gen.seed(1234567)
+        self.assertEqual(self.gen.getrandbits(MyIndex(100)),
+                         97904845777343510404718956115)
 
     def test_getrandbits_2G_bits(self):
         size = 2**31

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to