This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: random.Random(False) weird error
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: hroncok, loganjerry, mark.dickinson, rhettinger, vstinner
Priority: normal Keywords:

Created on 2020-03-09 20:21 by loganjerry, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg363766 - (view) Author: Jerry James (loganjerry) Date: 2020-03-09 20:21
Python 3.8:

>>> import random
>>> r = random.Random(False)
>>> r
<random.Random object at 0x5611716e8b00>

Python 3.9 alpha 4:

>>> import random
>>> r = random.Random(False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.9/random.py", line 100, in __init__
    self.seed(x)
  File "/usr/lib64/python3.9/random.py", line 163, in seed
    super().seed(a)
TypeError: descriptor '__abs__' of 'int' object needs an argument

This arose in the context of Fedora builds with python 3.9.  The networkx project reversed two arguments, resulting in False being passed to random.Random instead of the intended seed value.  I'm glad we noticed the problem with 3.9 so the intended value will now be used, but that TypeError message doesn't really indicate the nature of the problem.  Could you arrange for a better message?
msg363769 - (view) Author: Miro Hrončok (hroncok) * Date: 2020-03-09 20:44
Possibly related to https://bugs.python.org/issue32554 https://github.com/python/cpython/pull/15382 Deprecate hashing arbitrary types in random.seed()
msg363772 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2020-03-09 20:54
The lines here look odd to me: https://github.com/python/cpython/blob/363fab83b8a0e6d924c7a7c577feec6a2812bb8c/Modules/_randommodule.c#L290-L291

    args[0] = arg;
    n = PyObject_Vectorcall(_randomstate_global->Long___abs__, args, 0,
                                         NULL);

Should that 0 in the PyObject_Vectorcall be a 1 instead?
msg363820 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-10 11:50
> Should that 0 in the PyObject_Vectorcall be a 1 instead?

Right. I proposed PR 18897 to fix it and add an unit test on seed(False).
msg363824 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-03-10 14:15
Fixed by:

New changeset 00d7cd8ab8db2c1e1f591ade828f88a1a973d70f by Victor Stinner in branch 'master':
bpo-38075: Fix random_seed(): use PyObject_CallOneArg() (GH-18897)
https://github.com/python/cpython/commit/00d7cd8ab8db2c1e1f591ade828f88a1a973d70f
History
Date User Action Args
2022-04-11 14:59:27adminsetgithub: 84099
2020-03-10 14:15:58vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg363824

stage: resolved
2020-03-10 11:50:55vstinnersetmessages: + msg363820
2020-03-09 20:54:52mark.dickinsonsetnosy: + mark.dickinson
messages: + msg363772
2020-03-09 20:46:16vstinnersetnosy: + rhettinger
2020-03-09 20:44:49hroncoksetnosy: + vstinner, hroncok
messages: + msg363769
2020-03-09 20:21:50loganjerrycreate