[Python-checkins] cpython: Two minor Argument Clinic bugfixes: use the name of the class in the

larry.hastings python-checkins at python.org
Wed Jan 22 12:06:13 CET 2014


http://hg.python.org/cpython/rev/9bbb64e91913
changeset:   88634:9bbb64e91913
user:        Larry Hastings <larry at hastings.org>
date:        Wed Jan 22 03:05:49 2014 -0800
summary:
  Two minor Argument Clinic bugfixes: use the name of the class in the
docstring for __new__ and __init__, and always use "goto exit" instead of
returning "NULL" for failure to parse (as _new__ and __init__ return ints).

files:
  Modules/_cursesmodule.c |  13 +++++++------
  Modules/_dbmmodule.c    |   9 +++++----
  Modules/_opcode.c       |   8 ++++----
  Modules/_pickle.c       |   8 ++++----
  Modules/zlibmodule.c    |   9 +++++----
  Tools/clinic/clinic.py  |  10 +++++++---
  6 files changed, 32 insertions(+), 25 deletions(-)


diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -621,36 +621,37 @@
     switch (PyTuple_GET_SIZE(args)) {
         case 1:
             if (!PyArg_ParseTuple(args, "O:addch", &ch))
-                return NULL;
+                goto exit;
             break;
         case 2:
             if (!PyArg_ParseTuple(args, "Ol:addch", &ch, &attr))
-                return NULL;
+                goto exit;
             group_right_1 = 1;
             break;
         case 3:
             if (!PyArg_ParseTuple(args, "iiO:addch", &x, &y, &ch))
-                return NULL;
+                goto exit;
             group_left_1 = 1;
             break;
         case 4:
             if (!PyArg_ParseTuple(args, "iiOl:addch", &x, &y, &ch, &attr))
-                return NULL;
+                goto exit;
             group_right_1 = 1;
             group_left_1 = 1;
             break;
         default:
             PyErr_SetString(PyExc_TypeError, "curses.window.addch requires 1 to 4 arguments");
-            return NULL;
+            goto exit;
     }
     return_value = curses_window_addch_impl(self, group_left_1, x, y, ch, group_right_1, attr);
 
+exit:
     return return_value;
 }
 
 static PyObject *
 curses_window_addch_impl(PyObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr)
-/*[clinic end generated code: checksum=b073327add8197b6ba7fb96c87062422c8312954]*/
+/*[clinic end generated code: checksum=53d44d79791b30950972b3256bdd464f7426bf82]*/
 {
     PyCursesWindowObject *cwself = (PyCursesWindowObject *)self;
     int coordinates_group = group_left_1;
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -300,25 +300,26 @@
     switch (PyTuple_GET_SIZE(args)) {
         case 1:
             if (!PyArg_ParseTuple(args, "s#:get", &key, &key_length))
-                return NULL;
+                goto exit;
             break;
         case 2:
             if (!PyArg_ParseTuple(args, "s#O:get", &key, &key_length, &default_value))
-                return NULL;
+                goto exit;
             group_right_1 = 1;
             break;
         default:
             PyErr_SetString(PyExc_TypeError, "dbm.dbm.get requires 1 to 2 arguments");
-            return NULL;
+            goto exit;
     }
     return_value = dbm_dbm_get_impl((dbmobject *)self, key, key_length, group_right_1, default_value);
 
+exit:
     return return_value;
 }
 
 static PyObject *
 dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, int group_right_1, PyObject *default_value)
-/*[clinic end generated code: checksum=2c3209571267017f1b9abbd19e1b521849fd5d4a]*/
+/*[clinic end generated code: checksum=ca8bf63ec226e71d3cf390749777f7d5b7361478]*/
 {
     datum dbm_key, val;
 
diff --git a/Modules/_opcode.c b/Modules/_opcode.c
--- a/Modules/_opcode.c
+++ b/Modules/_opcode.c
@@ -42,16 +42,16 @@
     switch (PyTuple_GET_SIZE(args)) {
         case 1:
             if (!PyArg_ParseTuple(args, "i:stack_effect", &opcode))
-                return NULL;
+                goto exit;
             break;
         case 2:
             if (!PyArg_ParseTuple(args, "ii:stack_effect", &opcode, &oparg))
-                return NULL;
+                goto exit;
             group_right_1 = 1;
             break;
         default:
             PyErr_SetString(PyExc_TypeError, "_opcode.stack_effect requires 1 to 2 arguments");
-            return NULL;
+            goto exit;
     }
     _return_value = _opcode_stack_effect_impl(module, opcode, group_right_1, oparg);
     if ((_return_value == -1) && PyErr_Occurred())
@@ -64,7 +64,7 @@
 
 static int
 _opcode_stack_effect_impl(PyModuleDef *module, int opcode, int group_right_1, int oparg)
-/*[clinic end generated code: checksum=47e76ec27523da4ab192713642d32482cd743aa4]*/
+/*[clinic end generated code: checksum=58fb4f1b174fc92f783dc945ca712fb752a6c283]*/
 {
     int effect;
     if (HAS_ARG(opcode)) {
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -4044,7 +4044,7 @@
 [clinic start generated code]*/
 
 PyDoc_STRVAR(_pickle_Pickler___init____doc__,
-"__init__(file, protocol=None, fix_imports=True)\n"
+"Pickler(file, protocol=None, fix_imports=True)\n"
 "This takes a binary file for writing a pickle data stream.\n"
 "\n"
 "The optional *protocol* argument tells the pickler to use the given\n"
@@ -4088,7 +4088,7 @@
 
 static int
 _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *protocol, int fix_imports)
-/*[clinic end generated code: checksum=10c8ea05194d08108471163d8202cf5e12975544]*/
+/*[clinic end generated code: checksum=d10dfb463511430b4faad9fca07627041a35b96e]*/
 {
     _Py_IDENTIFIER(persistent_id);
     _Py_IDENTIFIER(dispatch_table);
@@ -6581,7 +6581,7 @@
 [clinic start generated code]*/
 
 PyDoc_STRVAR(_pickle_Unpickler___init____doc__,
-"__init__(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n"
+"Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n"
 "This takes a binary file for reading a pickle data stream.\n"
 "\n"
 "The protocol version of the pickle is detected automatically, so no\n"
@@ -6628,7 +6628,7 @@
 
 static int
 _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, int fix_imports, const char *encoding, const char *errors)
-/*[clinic end generated code: checksum=6936e9188104e45b1b15e1c11fe77b3965409471]*/
+/*[clinic end generated code: checksum=eb1a2cfc7b6f97c33980cff3d3b97d184a382f02]*/
 {
     _Py_IDENTIFIER(persistent_load);
 
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -205,19 +205,20 @@
     switch (PyTuple_GET_SIZE(args)) {
         case 1:
             if (!PyArg_ParseTuple(args, "y*:compress", &bytes))
-                return NULL;
+                goto exit;
             break;
         case 2:
             if (!PyArg_ParseTuple(args, "y*i:compress", &bytes, &level))
-                return NULL;
+                goto exit;
             group_right_1 = 1;
             break;
         default:
             PyErr_SetString(PyExc_TypeError, "zlib.compress requires 1 to 2 arguments");
-            return NULL;
+            goto exit;
     }
     return_value = zlib_compress_impl(module, &bytes, group_right_1, level);
 
+exit:
     /* Cleanup for bytes */
     if (bytes.obj)
        PyBuffer_Release(&bytes);
@@ -227,7 +228,7 @@
 
 static PyObject *
 zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int level)
-/*[clinic end generated code: checksum=66c4d16d0b8b9dd423648d9ef00d6a89d3363665]*/
+/*[clinic end generated code: checksum=74648f97e6b9d3cc9cd568d47262d462bded7ed0]*/
 {
     PyObject *ReturnVal = NULL;
     Byte *input, *output = NULL;
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -913,7 +913,7 @@
             s = """
     case {count}:
         if (!PyArg_ParseTuple(args, "{format_units}:{name}", {parse_arguments}))
-            return NULL;
+            goto exit;
         {group_booleans}
         break;
 """[1:]
@@ -924,7 +924,7 @@
         add("    default:\n")
         s = '        PyErr_SetString(PyExc_TypeError, "{} requires {} to {} arguments");\n'
         add(s.format(f.full_name, count_min, count_max))
-        add('        return NULL;\n')
+        add('        goto exit;\n')
         add("}}")
         template_dict['option_group_parsing'] = output()
 
@@ -3401,7 +3401,11 @@
         ## docstring first line
         ##
 
-        add(f.name)
+        if f.kind in (METHOD_NEW, METHOD_INIT):
+            assert f.cls
+            add(f.cls.name)
+        else:
+            add(f.name)
         add('(')
 
         # populate "right_bracket_count" field for every parameter

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list