[issue40346] Redesign random.Random class inheritance

2020-04-21 Thread Tim Peters
Tim Peters added the comment: This wasn't written with subclassing in mind to begin with. A class was just an obvious way to allow advanced users to construct instances with their own states (e.g., so they could build pseudo-independent generators for parallel programming). When SystemRand

[issue40346] Redesign random.Random class inheritance

2020-04-21 Thread Raymond Hettinger
Raymond Hettinger added the comment: -1 I am opposed to this redesign. There is no problem being solved that warrants changing a long standing public API. It is irresponsible to just guess at whether anyone is using the API. To add randbytes() could have just been a simple two line addi

[issue40346] Redesign random.Random class inheritance

2020-04-21 Thread STINNER Victor
STINNER Victor added the comment: > It may be time to start emitting a warning if a Random subclass overrides > random() but not getrandbits() or vice versa. Does someone know if there are users outside the stdlib of random subclass which only implements random()? I guess that a deprecation

[issue40346] Redesign random.Random class inheritance

2020-04-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It may be time to start emitting a warning if a Random subclass overrides random() but not getrandbits() or vice versa. If you only override random(), methods which rely on generating random integers will use worse algorithm (slightly less uniform). If you

[issue40346] Redesign random.Random class inheritance

2020-04-21 Thread STINNER Victor
STINNER Victor added the comment: Example with Python 3.8: --- import random class MyRandom(random.Random): def getrandbits(self, n): return 0 my = MyRandom() print([my.randint(1, 6) for _ in range(3)]) print([my.random() for _ in range(3)]) --- Output: --- [1, 1, 1] [0.565464179

[issue40346] Redesign random.Random class inheritance

2020-04-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: Having SystemRandom() use less memory is nice. The seed() logic is reusable (not MT specific) and should be kept. Historically, subclassers were supposed to supply random(), and the getrandbits() method was optional and just added greater range to randr

[issue40346] Redesign random.Random class inheritance

2020-04-20 Thread STINNER Victor
STINNER Victor added the comment: Attached PR 19631 adds random.BaseRandom. random.SystemRandom now inherits from BaseRandom and so no longer inherits from _random.Random: an instance now only takes 48 bytes of memory, rather than 2568 bytes (on x86-64). -- _

[issue40346] Redesign random.Random class inheritance

2020-04-20 Thread STINNER Victor
Change by STINNER Victor : -- pull_requests: +18958 pull_request: https://github.com/python/cpython/pull/19631 ___ Python tracker ___ __

[issue40346] Redesign random.Random class inheritance

2020-04-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: The randbytes() method could have been added effortlessly as a one line pure python method. It only became complicated as a result of premature optimization into C code and as a result of ignoring the API promises. You really don't have to redesign the w

[issue40346] Redesign random.Random class inheritance

2020-04-20 Thread STINNER Victor
Change by STINNER Victor : -- pull_requests: -18957 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://

[issue40346] Redesign random.Random class inheritance

2020-04-20 Thread Antoine Pitrou
Change by Antoine Pitrou : -- keywords: +patch nosy: +pitrou nosy_count: 1.0 -> 2.0 pull_requests: +18957 stage: -> patch review pull_request: https://github.com/python/cpython/pull/19539 ___ Python tracker

[issue40346] Redesign random.Random class inheritance

2020-04-20 Thread STINNER Victor
Change by STINNER Victor : -- title: Redesign random class inheritance -> Redesign random.Random class inheritance ___ Python tracker ___ _