Skip to content

Commit 4d85953

Browse files
committed
dictionary() constructor:
+ Change keyword arg name from "x" to "items". People passing a mapping object can stretch their imaginations <wink>. + Simplify the docstring text.
1 parent c2f0112 commit 4d85953

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

Lib/test/test_descr.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ def dict_constructor():
178178
vereq(d, {})
179179
d = dictionary({})
180180
vereq(d, {})
181-
d = dictionary(x={})
181+
d = dictionary(items={})
182182
vereq(d, {})
183183
d = dictionary({1: 2, 'a': 'b'})
184184
vereq(d, {1: 2, 'a': 'b'})
185185
vereq(d, dictionary(d.items()))
186-
vereq(d, dictionary(x=d.iteritems()))
186+
vereq(d, dictionary(items=d.iteritems()))
187187
for badarg in 0, 0L, 0j, "0", [0], (0,):
188188
try:
189189
dictionary(badarg)
@@ -226,7 +226,7 @@ class Mapping:
226226

227227
Mapping.keys = lambda self: self.dict.keys()
228228
Mapping.__getitem__ = lambda self, i: self.dict[i]
229-
d = dictionary(x=Mapping())
229+
d = dictionary(items=Mapping())
230230
vereq(d, Mapping.dict)
231231

232232
# Init from sequence of iterable objects, each producing a 2-sequence.
@@ -1865,7 +1865,7 @@ def keywords():
18651865
vereq(unicode(string='abc', errors='strict'), u'abc')
18661866
vereq(tuple(sequence=range(3)), (0, 1, 2))
18671867
vereq(list(sequence=(0, 1, 2)), range(3))
1868-
vereq(dictionary(x={1: 2}), {1: 2})
1868+
vereq(dictionary(items={1: 2}), {1: 2})
18691869

18701870
for constructor in (int, float, long, complex, str, unicode,
18711871
tuple, list, dictionary, file):

Objects/dictobject.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ static int
17811781
dict_init(PyObject *self, PyObject *args, PyObject *kwds)
17821782
{
17831783
PyObject *arg = NULL;
1784-
static char *kwlist[] = {"x", 0};
1784+
static char *kwlist[] = {"items", 0};
17851785
int result = 0;
17861786

17871787
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:dictionary",
@@ -1807,12 +1807,10 @@ static char dictionary_doc[] =
18071807
"dictionary() -> new empty dictionary.\n"
18081808
"dictionary(mapping) -> new dict initialized from a mapping object's\n"
18091809
" (key, value) pairs.\n"
1810-
"dictionary(seq) -> new dict initialized from the 2-element elements of\n"
1811-
" a sequence; for example, from mapping.items(). seq must be an\n"
1812-
" iterable object, producing iterable objects each producing exactly\n"
1813-
" two objects, the first of which is used as a key and the second as\n"
1814-
" its value. If a given key is seen more than once, the dict retains\n"
1815-
" the last value associated with it.";
1810+
"dictionary(seq) -> new dict initialized as if via:\n"
1811+
" d = {}\n"
1812+
" for k, v in seq:\n"
1813+
" d[k] = v";
18161814

18171815
PyTypeObject PyDict_Type = {
18181816
PyObject_HEAD_INIT(&PyType_Type)

0 commit comments

Comments
 (0)