summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAMIR <31338382+amiremohamadi@users.noreply.github.com>2020-12-21 23:45:50 (GMT)
committerGitHub <noreply@github.com>2020-12-21 23:45:50 (GMT)
commitb8fde8b5418b75d2935d0ff93b20d45d5350f206 (patch)
tree5a02911a3c8ea448fe7b56e436513f1f466457d7 /Modules
parent711381dfb09fbd434cc3b404656f7fd306161a64 (diff)
downloadcpython-b8fde8b5418b75d2935d0ff93b20d45d5350f206.zip
cpython-b8fde8b5418b75d2935d0ff93b20d45d5350f206.tar.gz
cpython-b8fde8b5418b75d2935d0ff93b20d45d5350f206.tar.bz2
bpo-42008: Fix internal _random.Random() seeding for the one argument case (GH-22668)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_randommodule.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index ad4fd47..99be69c 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -519,6 +519,7 @@ random_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
RandomObject *self;
PyObject *tmp;
+ PyObject *arg = NULL;
_randomstate *state = _randomstate_type(type);
if (type == (PyTypeObject*)state->Random_Type &&
@@ -529,12 +530,22 @@ random_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self = (RandomObject *)PyType_GenericAlloc(type, 0);
if (self == NULL)
return NULL;
- tmp = random_seed(self, args);
+
+ if (PyTuple_GET_SIZE(args) > 1) {
+ PyErr_SetString(PyExc_TypeError, "Random() requires 0 or 1 argument");
+ return NULL;
+ }
+
+ if (PyTuple_GET_SIZE(args) == 1)
+ arg = PyTuple_GET_ITEM(args, 0);
+
+ tmp = random_seed(self, arg);
if (tmp == NULL) {
Py_DECREF(self);
return NULL;
}
Py_DECREF(tmp);
+
return (PyObject *)self;
}