]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117764: Fix and add signatures for many builtins (GH-117769)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 12 Apr 2024 10:56:41 +0000 (13:56 +0300)
committerGitHub <noreply@github.com>
Fri, 12 Apr 2024 10:56:41 +0000 (13:56 +0300)
Objects/clinic/descrobject.c.h
Objects/descrobject.c
Objects/genericaliasobject.c
Objects/memoryobject.c
Objects/namespaceobject.c
Objects/rangeobject.c
Objects/typeobject.c
Python/bltinmodule.c
Python/clinic/bltinmodule.c.h
Python/clinic/traceback.c.h
Python/traceback.c

index 02fb440d9c83af89d2a078875153f571bc736c0a..d79be80d3ec1656c5e451bafd5e25508f2bde2eb 100644 (file)
@@ -8,6 +8,12 @@ preserve
 #endif
 #include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
 
+PyDoc_STRVAR(mappingproxy_new__doc__,
+"mappingproxy(mapping)\n"
+"--\n"
+"\n"
+"Read-only proxy of a mapping.");
+
 static PyObject *
 mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping);
 
@@ -167,4 +173,4 @@ skip_optional_pos:
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=a4664ccf3da10f5a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=050e331316a04207 input=a9049054013a1b77]*/
index 3423f152ce862ddf5d0938d856e0243a2bd6cef4..029318faf0acd2392e9e1b2dad5973dc0bb3c084 100644 (file)
@@ -1165,8 +1165,8 @@ mappingproxy_reversed(PyObject *self, PyObject *Py_UNUSED(ignored))
 
 static PyMethodDef mappingproxy_methods[] = {
     {"get",       _PyCFunction_CAST(mappingproxy_get), METH_FASTCALL,
-     PyDoc_STR("D.get(k[,d]) -> D[k] if k in D, else d."
-               "  d defaults to None.")},
+     PyDoc_STR("get($self, key, default=None, /)\n--\n\n"
+        "Return the value for key if key is in the mapping, else default.")},
     {"keys",      mappingproxy_keys,       METH_NOARGS,
      PyDoc_STR("D.keys() -> a set-like object providing a view on D's keys")},
     {"values",    mappingproxy_values,     METH_NOARGS,
@@ -1254,11 +1254,12 @@ mappingproxy.__new__ as mappingproxy_new
 
     mapping: object
 
+Read-only proxy of a mapping.
 [clinic start generated code]*/
 
 static PyObject *
 mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping)
-/*[clinic end generated code: output=65f27f02d5b68fa7 input=d2d620d4f598d4f8]*/
+/*[clinic end generated code: output=65f27f02d5b68fa7 input=c156df096ef7590c]*/
 {
     mappingproxyobject *mappingproxy;
 
@@ -2024,7 +2025,7 @@ PyTypeObject PyDictProxy_Type = {
     0,                                          /* tp_as_buffer */
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
         Py_TPFLAGS_MAPPING,                     /* tp_flags */
-    0,                                          /* tp_doc */
+    mappingproxy_new__doc__,                    /* tp_doc */
     mappingproxy_traverse,                      /* tp_traverse */
     0,                                          /* tp_clear */
     mappingproxy_richcompare,                   /* tp_richcompare */
index c045d495e8552655be739884310ea2e1d64ecc9f..2779baf0bd1c61fd35e0cfa345ea9dae4844a069 100644 (file)
@@ -537,6 +537,8 @@ _Py_subs_parameters(PyObject *self, PyObject *args, PyObject *parameters, PyObje
 }
 
 PyDoc_STRVAR(genericalias__doc__,
+"GenericAlias(origin, args, /)\n"
+"--\n\n"
 "Represent a PEP 585 generic type\n"
 "\n"
 "E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).");
index 6a38952fdc1f3bc9a3c2d2432b14d9a487986c1a..5caa6504272301ba64ea9442fdab389ce819aa0b 100644 (file)
@@ -3255,6 +3255,9 @@ PyDoc_STRVAR(memory_f_contiguous_doc,
              "A bool indicating whether the memory is Fortran contiguous.");
 PyDoc_STRVAR(memory_contiguous_doc,
              "A bool indicating whether the memory is contiguous.");
+PyDoc_STRVAR(memory_exit_doc,
+             "__exit__($self, /, *exc_info)\n--\n\n"
+             "Release the underlying buffer exposed by the memoryview object.");
 
 
 static PyGetSetDef memory_getsetlist[] = {
@@ -3283,7 +3286,7 @@ static PyMethodDef memory_methods[] = {
     MEMORYVIEW_TOREADONLY_METHODDEF
     MEMORYVIEW__FROM_FLAGS_METHODDEF
     {"__enter__",   memory_enter, METH_NOARGS, NULL},
-    {"__exit__",    memory_exit, METH_VARARGS, NULL},
+    {"__exit__",    memory_exit, METH_VARARGS, memory_exit_doc},
     {NULL,          NULL}
 };
 
index a6b02fd011cf4f45fbb00a4e6b64a33864ef1082..b2a224b9b2bda50ca4b4c274a6650a1c60c9097a 100644 (file)
@@ -227,9 +227,9 @@ static PyMethodDef namespace_methods[] = {
 
 
 PyDoc_STRVAR(namespace_doc,
-"A simple attribute-based namespace.\n\
-\n\
-SimpleNamespace(**kwargs)");
+"SimpleNamespace(**kwargs)\n\
+--\n\n\
+A simple attribute-based namespace.");
 
 PyTypeObject _PyNamespace_Type = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
index ce9eef69ad75a8289db06277e8d975ca9d70e84e..7da6162744ffd6fc360debd5b3c99a019688e4ba 100644 (file)
@@ -751,7 +751,7 @@ PyDoc_STRVAR(index_doc,
 
 static PyMethodDef range_methods[] = {
     {"__reversed__",    range_reverse,              METH_NOARGS, reverse_doc},
-    {"__reduce__",      (PyCFunction)range_reduce,  METH_VARARGS},
+    {"__reduce__",      (PyCFunction)range_reduce,  METH_NOARGS},
     {"count",           (PyCFunction)range_count,   METH_O,      count_doc},
     {"index",           (PyCFunction)range_index,   METH_O,      index_doc},
     {NULL,              NULL}           /* sentinel */
index 3f38abfcfe5b11c04ea8ae1ceb23a31cf901553f..ee0286e4009ec44025b4f41a96250049dfb0ced7 100644 (file)
@@ -6917,7 +6917,7 @@ static PyMethodDef object_methods[] = {
     OBJECT___REDUCE_EX___METHODDEF
     OBJECT___REDUCE___METHODDEF
     OBJECT___GETSTATE___METHODDEF
-    {"__subclasshook__", object_subclasshook, METH_CLASS | METH_VARARGS,
+    {"__subclasshook__", object_subclasshook, METH_CLASS | METH_O,
      object_subclasshook_doc},
     {"__init_subclass__", object_init_subclass, METH_CLASS | METH_NOARGS,
      object_init_subclass_doc},
@@ -9893,7 +9893,8 @@ static pytype_slotdef slotdefs[] = {
     TPSLOT(__getattribute__, tp_getattro, _Py_slot_tp_getattr_hook,
            wrap_binaryfunc,
            "__getattribute__($self, name, /)\n--\n\nReturn getattr(self, name)."),
-    TPSLOT(__getattr__, tp_getattro, _Py_slot_tp_getattr_hook, NULL, ""),
+    TPSLOT(__getattr__, tp_getattro, _Py_slot_tp_getattr_hook, NULL,
+           "__getattr__($self, name, /)\n--\n\nImplement getattr(self, name)."),
     TPSLOT(__setattr__, tp_setattro, slot_tp_setattro, wrap_setattr,
            "__setattr__($self, name, value, /)\n--\n\nImplement setattr(self, name, value)."),
     TPSLOT(__delattr__, tp_setattro, slot_tp_setattro, wrap_delattr,
@@ -9928,7 +9929,9 @@ static pytype_slotdef slotdefs[] = {
     TPSLOT(__new__, tp_new, slot_tp_new, NULL,
            "__new__(type, /, *args, **kwargs)\n--\n\n"
            "Create and return new object.  See help(type) for accurate signature."),
-    TPSLOT(__del__, tp_finalize, slot_tp_finalize, (wrapperfunc)wrap_del, ""),
+    TPSLOT(__del__, tp_finalize, slot_tp_finalize, (wrapperfunc)wrap_del,
+           "__del__($self, /)\n--\n\n"
+           "Called when the instance is about to be destroyed."),
 
     BUFSLOT(__buffer__, bf_getbuffer, slot_bf_getbuffer, wrap_buffer,
             "__buffer__($self, flags, /)\n--\n\n"
index f66a8c07c6f872b645d724adc855d7137898d5a3..7af3ac9c5158d6efe59df804812bdac05d7e6de2 100644 (file)
@@ -475,7 +475,7 @@ builtin_breakpoint(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyOb
 }
 
 PyDoc_STRVAR(breakpoint_doc,
-"breakpoint(*args, **kws)\n\
+"breakpoint($module, /, *args, **kws)\n\
 --\n\
 \n\
 Call sys.breakpointhook(*args, **kws).  sys.breakpointhook() must accept\n\
@@ -1703,16 +1703,16 @@ anext as builtin_anext
     default: object = NULL
     /
 
-async anext(aiterator[, default])
+Return the next item from the async iterator.
 
-Return the next item from the async iterator.  If default is given and the async
-iterator is exhausted, it is returned instead of raising StopAsyncIteration.
+If default is given and the async iterator is exhausted,
+it is returned instead of raising StopAsyncIteration.
 [clinic start generated code]*/
 
 static PyObject *
 builtin_anext_impl(PyObject *module, PyObject *aiterator,
                    PyObject *default_value)
-/*[clinic end generated code: output=f02c060c163a81fa input=8f63f4f78590bb4c]*/
+/*[clinic end generated code: output=f02c060c163a81fa input=2900e4a370d39550]*/
 {
     PyTypeObject *t;
     PyObject *awaitable;
index 3898f987cd61ea67834a2662b6a1e44070c038b8..3f005bcbfb6a1a29252a59772e215c6618de27af 100644 (file)
@@ -693,10 +693,10 @@ PyDoc_STRVAR(builtin_anext__doc__,
 "anext($module, aiterator, default=<unrepresentable>, /)\n"
 "--\n"
 "\n"
-"async anext(aiterator[, default])\n"
+"Return the next item from the async iterator.\n"
 "\n"
-"Return the next item from the async iterator.  If default is given and the async\n"
-"iterator is exhausted, it is returned instead of raising StopAsyncIteration.");
+"If default is given and the async iterator is exhausted,\n"
+"it is returned instead of raising StopAsyncIteration.");
 
 #define BUILTIN_ANEXT_METHODDEF    \
     {"anext", _PyCFunction_CAST(builtin_anext), METH_FASTCALL, builtin_anext__doc__},
@@ -1193,4 +1193,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=643a8d5f900e0c36 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6d15edfc194b2c08 input=a9049054013a1b77]*/
index aee08d6ad97047e3e77e11752ab02ec588c35d0d..fe53a2786d1ad67a0b4b70a42c726776f5aeb71f 100644 (file)
@@ -9,7 +9,7 @@ preserve
 #include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
 
 PyDoc_STRVAR(tb_new__doc__,
-"TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)\n"
+"traceback(tb_next, tb_frame, tb_lasti, tb_lineno)\n"
 "--\n"
 "\n"
 "Create a new traceback object.");
@@ -43,7 +43,7 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     static const char * const _keywords[] = {"tb_next", "tb_frame", "tb_lasti", "tb_lineno", NULL};
     static _PyArg_Parser _parser = {
         .keywords = _keywords,
-        .fname = "TracebackType",
+        .fname = "traceback",
         .kwtuple = KWTUPLE,
     };
     #undef KWTUPLE
@@ -61,7 +61,7 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     }
     tb_next = fastargs[0];
     if (!PyObject_TypeCheck(fastargs[1], &PyFrame_Type)) {
-        _PyArg_BadArgument("TracebackType", "argument 'tb_frame'", (&PyFrame_Type)->tp_name, fastargs[1]);
+        _PyArg_BadArgument("traceback", "argument 'tb_frame'", (&PyFrame_Type)->tp_name, fastargs[1]);
         goto exit;
     }
     tb_frame = (PyFrameObject *)fastargs[1];
@@ -78,4 +78,4 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=4e2f6b935841b09c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=916a759875507c5a input=a9049054013a1b77]*/
index 2564a7db5dcfec327d5d0e0226b018237eaf14a0..47b77c9108dd9a78fef6acbae21738e9305de803 100644 (file)
@@ -34,9 +34,9 @@
 extern char* _PyTokenizer_FindEncodingFilename(int, PyObject *);
 
 /*[clinic input]
-class TracebackType "PyTracebackObject *" "&PyTraceback_Type"
+class traceback "PyTracebackObject *" "&PyTraceback_Type"
 [clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=928fa06c10151120]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=cf96294b2bebc811]*/
 
 #include "clinic/traceback.c.h"
 
@@ -63,7 +63,7 @@ tb_create_raw(PyTracebackObject *next, PyFrameObject *frame, int lasti,
 
 /*[clinic input]
 @classmethod
-TracebackType.__new__ as tb_new
+traceback.__new__ as tb_new
 
   tb_next: object
   tb_frame: object(type='PyFrameObject *', subclass_of='&PyFrame_Type')
@@ -76,7 +76,7 @@ Create a new traceback object.
 static PyObject *
 tb_new_impl(PyTypeObject *type, PyObject *tb_next, PyFrameObject *tb_frame,
             int tb_lasti, int tb_lineno)
-/*[clinic end generated code: output=fa077debd72d861a input=01cbe8ec8783fca7]*/
+/*[clinic end generated code: output=fa077debd72d861a input=b88143145454cb59]*/
 {
     if (tb_next == Py_None) {
         tb_next = NULL;