Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random.Random(False) weird error #84099

Closed
jamesjer mannequin opened this issue Mar 9, 2020 · 5 comments
Closed

random.Random(False) weird error #84099

jamesjer mannequin opened this issue Mar 9, 2020 · 5 comments
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@jamesjer
Copy link
Mannequin

jamesjer mannequin commented Mar 9, 2020

BPO 39918
Nosy @rhettinger, @mdickinson, @vstinner, @hroncok, @jamesjer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-03-10.14:15:58.963>
created_at = <Date 2020-03-09.20:21:50.771>
labels = ['type-bug', 'library', '3.9']
title = 'random.Random(False) weird error'
updated_at = <Date 2020-03-10.14:15:58.962>
user = 'https://github.com/jamesjer'

bugs.python.org fields:

activity = <Date 2020-03-10.14:15:58.962>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2020-03-10.14:15:58.963>
closer = 'vstinner'
components = ['Library (Lib)']
creation = <Date 2020-03-09.20:21:50.771>
creator = 'loganjerry'
dependencies = []
files = []
hgrepos = []
issue_num = 39918
keywords = []
message_count = 5.0
messages = ['363766', '363769', '363772', '363820', '363824']
nosy_count = 5.0
nosy_names = ['rhettinger', 'mark.dickinson', 'vstinner', 'hroncok', 'loganjerry']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue39918'
versions = ['Python 3.9']

@jamesjer
Copy link
Mannequin Author

jamesjer mannequin commented Mar 9, 2020

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?

@jamesjer jamesjer mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 9, 2020
@hroncok
Copy link
Mannequin

hroncok mannequin commented Mar 9, 2020

Possibly related to https://bugs.python.org/issue32554 #15382 Deprecate hashing arbitrary types in random.seed()

@mdickinson
Copy link
Member

The lines here look odd to me:

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

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

Should that 0 in the PyObject_Vectorcall be a 1 instead?

@vstinner
Copy link
Member

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).

@vstinner
Copy link
Member

Fixed by:

New changeset 00d7cd8 by Victor Stinner in branch 'master':
bpo-38075: Fix random_seed(): use PyObject_CallOneArg() (GH-18897)
00d7cd8

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants