Skip to content

Commit 88bcba4

Browse files
author
birkenfeld
committed
Disallow keyword arguments for type constructors that don't use them.
(fixes bug #1119418) git-svn-id: http://svn.python.org/projects/python/trunk@39400 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent d8e21d7 commit 88bcba4

File tree

13 files changed

+100
-13
lines changed

13 files changed

+100
-13
lines changed

Include/modsupport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ PyAPI_FUNC(int) PyArg_ParseTupleAndKeywords(PyObject *, PyObject *,
1515
char *, char **, ...);
1616
PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, char *, int, int, ...);
1717
PyAPI_FUNC(PyObject *) Py_BuildValue(char *, ...);
18+
PyAPI_FUNC(int) _PyArg_NoKeywords(char *funcname, PyObject *kw);
1819

1920
PyAPI_FUNC(int) PyArg_VaParse(PyObject *, char *, va_list);
2021
PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *,

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.5 alpha 1?
1212
Core and builtins
1313
-----------------
1414

15+
- Disallow keyword arguments for type constructors that don't use it
16+
(fixes bug #1119418).
17+
1518
- Forward UnicodeDecodeError into SyntaxError for source encoding errors.
1619

1720
- SF bug #900092: When tracing (e.g. for hotshot), restore 'return' events for

Modules/_randommodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ random_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
481481
RandomObject *self;
482482
PyObject *tmp;
483483

484+
if (!_PyArg_NoKeywords("Random()", kwds))
485+
return NULL;
486+
484487
self = (RandomObject *)type->tp_alloc(type, 0);
485488
if (self == NULL)
486489
return NULL;

Modules/arraymodule.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,18 +1799,9 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
17991799
char c;
18001800
PyObject *initial = NULL, *it = NULL;
18011801
struct arraydescr *descr;
1802-
1803-
if (kwds != NULL) {
1804-
int i = PyObject_Length(kwds);
1805-
if (i < 0)
1806-
return NULL;
1807-
else if (i > 0) {
1808-
PyErr_SetString(PyExc_TypeError,
1809-
"array.array constructor takes "
1810-
"no keyword arguments");
1811-
return NULL;
1812-
}
1813-
}
1802+
1803+
if (!_PyArg_NoKeywords("array.array()", kwds))
1804+
return NULL;
18141805

18151806
if (!PyArg_ParseTuple(args, "c|O:array", &c, &initial))
18161807
return NULL;

Modules/collectionsmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ deque_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
9595
dequeobject *deque;
9696
block *b;
9797

98+
if (!_PyArg_NoKeywords("deque()", kwds))
99+
return NULL;
100+
98101
/* create dequeobject structure */
99102
deque = (dequeobject *)type->tp_alloc(type, 0);
100103
if (deque == NULL)

Modules/itertoolsmodule.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,9 @@ cycle_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
618618
PyObject *saved;
619619
cycleobject *lz;
620620

621+
if (!_PyArg_NoKeywords("cycle()", kwds))
622+
return NULL;
623+
621624
if (!PyArg_UnpackTuple(args, "cycle", 1, 1, &iterable))
622625
return NULL;
623626

@@ -765,6 +768,9 @@ dropwhile_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
765768
PyObject *it;
766769
dropwhileobject *lz;
767770

771+
if (!_PyArg_NoKeywords("dropwhile()", kwds))
772+
return NULL;
773+
768774
if (!PyArg_UnpackTuple(args, "dropwhile", 2, 2, &func, &seq))
769775
return NULL;
770776

@@ -906,6 +912,9 @@ takewhile_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
906912
PyObject *it;
907913
takewhileobject *lz;
908914

915+
if (!_PyArg_NoKeywords("takewhile()", kwds))
916+
return NULL;
917+
909918
if (!PyArg_UnpackTuple(args, "takewhile", 2, 2, &func, &seq))
910919
return NULL;
911920

@@ -1048,6 +1057,9 @@ islice_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
10481057
int numargs;
10491058
isliceobject *lz;
10501059

1060+
if (!_PyArg_NoKeywords("islice()", kwds))
1061+
return NULL;
1062+
10511063
if (!PyArg_UnpackTuple(args, "islice", 2, 4, &seq, &a1, &a2, &a3))
10521064
return NULL;
10531065

@@ -1236,6 +1248,9 @@ starmap_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
12361248
PyObject *it;
12371249
starmapobject *lz;
12381250

1251+
if (!_PyArg_NoKeywords("starmap()", kwds))
1252+
return NULL;
1253+
12391254
if (!PyArg_UnpackTuple(args, "starmap", 2, 2, &func, &seq))
12401255
return NULL;
12411256

@@ -1365,6 +1380,9 @@ imap_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
13651380
imapobject *lz;
13661381
int numargs, i;
13671382

1383+
if (!_PyArg_NoKeywords("imap()", kwds))
1384+
return NULL;
1385+
13681386
numargs = PyTuple_Size(args);
13691387
if (numargs < 2) {
13701388
PyErr_SetString(PyExc_TypeError,
@@ -1544,6 +1562,9 @@ chain_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
15441562
int i;
15451563
PyObject *ittuple;
15461564

1565+
if (!_PyArg_NoKeywords("chain()", kwds))
1566+
return NULL;
1567+
15471568
/* obtain iterators */
15481569
assert(PyTuple_Check(args));
15491570
ittuple = PyTuple_New(tuplesize);
@@ -1684,6 +1705,9 @@ ifilter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
16841705
PyObject *it;
16851706
ifilterobject *lz;
16861707

1708+
if (!_PyArg_NoKeywords("ifilter()", kwds))
1709+
return NULL;
1710+
16871711
if (!PyArg_UnpackTuple(args, "ifilter", 2, 2, &func, &seq))
16881712
return NULL;
16891713

@@ -1825,6 +1849,9 @@ ifilterfalse_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
18251849
PyObject *it;
18261850
ifilterfalseobject *lz;
18271851

1852+
if (!_PyArg_NoKeywords("ifilterfalse()", kwds))
1853+
return NULL;
1854+
18281855
if (!PyArg_UnpackTuple(args, "ifilterfalse", 2, 2, &func, &seq))
18291856
return NULL;
18301857

@@ -1964,6 +1991,9 @@ count_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
19641991
countobject *lz;
19651992
long cnt = 0;
19661993

1994+
if (!_PyArg_NoKeywords("count()", kwds))
1995+
return NULL;
1996+
19671997
if (!PyArg_ParseTuple(args, "|l:count", &cnt))
19681998
return NULL;
19691999

@@ -2060,6 +2090,9 @@ izip_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
20602090
PyObject *result;
20612091
int tuplesize = PySequence_Length(args);
20622092

2093+
if (!_PyArg_NoKeywords("izip()", kwds))
2094+
return NULL;
2095+
20632096
/* args must be a tuple */
20642097
assert(PyTuple_Check(args));
20652098

@@ -2240,6 +2273,9 @@ repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
22402273
PyObject *element;
22412274
long cnt = -1;
22422275

2276+
if (!_PyArg_NoKeywords("repeat()", kwds))
2277+
return NULL;
2278+
22432279
if (!PyArg_ParseTuple(args, "O|l:repeat", &element, &cnt))
22442280
return NULL;
22452281

Modules/operator.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
269269
PyObject *item;
270270
int nitems;
271271

272+
if (!_PyArg_NoKeywords("itemgetter()", kwds))
273+
return NULL;
274+
272275
nitems = PyTuple_GET_SIZE(args);
273276
if (nitems <= 1) {
274277
if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &item))
@@ -405,6 +408,9 @@ attrgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
405408
PyObject *attr;
406409
int nattrs;
407410

411+
if (!_PyArg_NoKeywords("attrgetter()", kwds))
412+
return NULL;
413+
408414
nattrs = PyTuple_GET_SIZE(args);
409415
if (nattrs <= 1) {
410416
if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &attr))

Modules/zipimport.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ zipimporter_init(ZipImporter *self, PyObject *args, PyObject *kwds)
6565
char *path, *p, *prefix, buf[MAXPATHLEN+2];
6666
int len;
6767

68+
if (!_PyArg_NoKeywords("zipimporter()", kwds))
69+
return -1;
70+
6871
if (!PyArg_ParseTuple(args, "s:zipimporter",
6972
&path))
7073
return -1;

Objects/bufferobject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ buffer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
192192
int offset = 0;
193193
int size = Py_END_OF_BUFFER;
194194

195-
if ( !PyArg_ParseTuple(args, "O|ii:buffer", &ob, &offset, &size) )
195+
if (!_PyArg_NoKeywords("buffer()", kw))
196+
return NULL;
197+
198+
if (!PyArg_ParseTuple(args, "O|ii:buffer", &ob, &offset, &size))
196199
return NULL;
197200
return PyBuffer_FromObject(ob, offset, size);
198201
}

Objects/rangeobject.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ range_new(PyTypeObject *type, PyObject *args, PyObject *kw)
4545
long ilow = 0, ihigh = 0, istep = 1;
4646
long n;
4747

48+
if (!_PyArg_NoKeywords("xrange()", kw))
49+
return NULL;
50+
4851
if (PyTuple_Size(args) <= 1) {
4952
if (!PyArg_ParseTuple(args,
5053
"l;xrange() requires 1-3 int arguments",

0 commit comments

Comments
 (0)