Skip to content

[2.7] bpo-31478: Prevent unwanted behavior in _random.Random.seed() in case the arg has a bad __abs__() method (GH-3596)#3845

Merged
serhiy-storchaka merged 5 commits into
python:2.7from
orenmn:bpo31478-backport27
Oct 2, 2017
Merged

[2.7] bpo-31478: Prevent unwanted behavior in _random.Random.seed() in case the arg has a bad __abs__() method (GH-3596)#3845
serhiy-storchaka merged 5 commits into
python:2.7from
orenmn:bpo31478-backport27

Conversation

@orenmn

@orenmn orenmn commented Oct 1, 2017

Copy link
Copy Markdown
Contributor
  • In case the argument of _random.Random.seed() is a long/int subclass, ignore its __abs__() method.
  • Add a test to test_random to verify that such __abs__() methods are indeed ignored.

https://bugs.python.org/issue31478

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a NEWS entry.

Comment thread Lib/test/test_random.py Outdated
expected_value = self.gen.random()
for seed_arg in [42L, BadInt(42), BadLong(42)]:
self.gen.seed(seed_arg)
self.assertEqual(expected_value, self.gen.random())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the actual value at left and the expected value at right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants