]> granicus.if.org Git - python/commitdiff
dictionary() constructor:
authorTim Peters <tim.peters@gmail.com>
Sat, 27 Oct 2001 18:27:48 +0000 (18:27 +0000)
committerTim Peters <tim.peters@gmail.com>
Sat, 27 Oct 2001 18:27:48 +0000 (18:27 +0000)
+ Change keyword arg name from "x" to "items".  People passing a mapping
  object can stretch their imaginations <wink>.
+ Simplify the docstring text.

Lib/test/test_descr.py
Objects/dictobject.c

index f5daf261dd7de0909c462ccce5d694c728c54cb6..97e92dad1f287663be349663412b2fa53fd32139 100644 (file)
@@ -178,12 +178,12 @@ def dict_constructor():
     vereq(d, {})
     d = dictionary({})
     vereq(d, {})
-    d = dictionary(x={})
+    d = dictionary(items={})
     vereq(d, {})
     d = dictionary({1: 2, 'a': 'b'})
     vereq(d, {1: 2, 'a': 'b'})
     vereq(d, dictionary(d.items()))
-    vereq(d, dictionary(x=d.iteritems()))
+    vereq(d, dictionary(items=d.iteritems()))
     for badarg in 0, 0L, 0j, "0", [0], (0,):
         try:
             dictionary(badarg)
@@ -226,7 +226,7 @@ def dict_constructor():
 
     Mapping.keys = lambda self: self.dict.keys()
     Mapping.__getitem__ = lambda self, i: self.dict[i]
-    d = dictionary(x=Mapping())
+    d = dictionary(items=Mapping())
     vereq(d, Mapping.dict)
 
     # Init from sequence of iterable objects, each producing a 2-sequence.
@@ -1865,7 +1865,7 @@ def keywords():
     vereq(unicode(string='abc', errors='strict'), u'abc')
     vereq(tuple(sequence=range(3)), (0, 1, 2))
     vereq(list(sequence=(0, 1, 2)), range(3))
-    vereq(dictionary(x={1: 2}), {1: 2})
+    vereq(dictionary(items={1: 2}), {1: 2})
 
     for constructor in (int, float, long, complex, str, unicode,
                         tuple, list, dictionary, file):
index f901499fe12ede0e5d689b987cba22fbd8401e04..167f901b237aaa8a42b8550e28153957b31ee4e9 100644 (file)
@@ -1781,7 +1781,7 @@ static int
 dict_init(PyObject *self, PyObject *args, PyObject *kwds)
 {
        PyObject *arg = NULL;
-       static char *kwlist[] = {"x", 0};
+       static char *kwlist[] = {"items", 0};
        int result = 0;
 
        if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:dictionary",
@@ -1807,12 +1807,10 @@ static char dictionary_doc[] =
 "dictionary() -> new empty dictionary.\n"
 "dictionary(mapping) -> new dict initialized from a mapping object's\n"
 "    (key, value) pairs.\n"
-"dictionary(seq) -> new dict initialized from the 2-element elements of\n"
-"    a sequence; for example, from mapping.items().  seq must be an\n"
-"    iterable object, producing iterable objects each producing exactly\n"
-"    two objects, the first of which is used as a key and the second as\n"
-"    its value.  If a given key is seen more than once, the dict retains\n"
-"    the last value associated with it.";
+"dictionary(seq) -> new dict initialized as if via:\n"
+"    d = {}\n"
+"    for k, v in seq:\n"
+"        d[k] = v";
 
 PyTypeObject PyDict_Type = {
        PyObject_HEAD_INIT(&PyType_Type)