cpython: 85710aa396ef (original) (raw)

--- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -429,6 +429,9 @@ function. Accepts a wide range of python callables, from plain functions and classes to :func:functools.partial objects.

--- a/Include/object.h +++ b/Include/object.h @@ -492,6 +492,9 @@ PyAPI_FUNC(PyTypeObject *) _PyType_Calcu PyAPI_FUNC(unsigned int) PyType_ClearCache(void); PyAPI_FUNC(void) PyType_Modified(PyTypeObject *); +PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *name, const char *internal_doc); +PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *name, const char internal_doc); + / Generic operations on objects */ struct _Py_Identifier; #ifndef Py_LIMITED_API

--- a/Lib/idlelib/idle_test/test_calltips.py +++ b/Lib/idlelib/idle_test/test_calltips.py @@ -55,24 +55,27 @@ class Get_signatureTest(unittest.TestCas gtest(list.new, 'T.new(S, ...) -> a new object with type S, a subtype of T') gtest(list.init,

def test_multiline_docstring(self): # Test fewer lines than max.

# Test max lines and line (currently) too long. self.assertEqual(signature(bytes), -"bytes(iterable_of_ints) -> bytes\n" "bytes(string, encoding[, errors]) -> bytes\n" "bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer\n" #bytes(int) -> bytes object of size given by the parameter initialized with null bytes

--- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1419,9 +1419,11 @@ def getgeneratorlocals(generator): _WrapperDescriptor = type(type.call) _MethodWrapper = type(all.call) +_ClassMethodWrapper = type(int.dict['from_bytes']) _NonUserDefinedCallables = (_WrapperDescriptor, _MethodWrapper,

@@ -1443,6 +1445,13 @@ def signature(obj): if not callable(obj): raise TypeError('{!r} is not a callable object'.format(obj))

+ if isinstance(obj, types.MethodType): # In this case we skip the first parameter of the underlying # function (usually self or cls). @@ -1460,13 +1469,9 @@ def signature(obj): if sig is not None: return sig - if isinstance(obj, types.FunctionType): return Signature.from_function(obj)

- if isinstance(obj, functools.partial): sig = signature(obj.func) @@ -2033,7 +2038,7 @@ class Signature: name = parse_name(name_node) if name is invalid: return None

@@ -2066,6 +2071,23 @@ class Signature: kind = Parameter.VAR_KEYWORD p(f.args.kwarg, empty)

+ return cls(parameters, return_annotation=cls.empty)

--- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -925,7 +925,10 @@ class HTMLDoc(Doc): anchor, name, reallink) argspec = None if inspect.isfunction(object) or inspect.isbuiltin(object):

@@ -1319,8 +1322,12 @@ location listed above. skipdocs = 1 title = self.bold(name) + ' = ' + realname argspec = None

+

--- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -125,7 +125,7 @@ class CAPITest(unittest.TestCase): self.assertEqual(_testcapi.docstring_no_signature.text_signature, None) self.assertEqual(_testcapi.docstring_with_invalid_signature.doc,

@@ -133,12 +133,12 @@ class CAPITest(unittest.TestCase): self.assertEqual(_testcapi.docstring_with_signature.doc, "This docstring has a valid signature.")

self.assertEqual(_testcapi.docstring_with_signature_and_extra_newlines.doc, "This docstring has a valid signature and some extra newlines.") self.assertEqual(_testcapi.docstring_with_signature_and_extra_newlines.text_signature,

@unittest.skipUnless(threading, 'Threading required for this test.')

--- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -436,8 +436,8 @@ From the Iterators list, about the types

[s for s in dir(i) if not s.startswith('_')] ['close', 'gi_code', 'gi_frame', 'gi_running', 'send', 'throw'] from test.support import HAVE_DOCSTRINGS ->>> print(i.next.doc if HAVE_DOCSTRINGS else 'x.next() <==> next(x)') -x.next() <==> next(x) +>>> print(i.next.doc if HAVE_DOCSTRINGS else 'Implements next(self).') +Implements next(self). iter(i) is i True import types

--- a/Lib/test/test_genexps.py +++ b/Lib/test/test_genexps.py @@ -222,8 +222,8 @@ Check that generator attributes are pres True >>> from test.support import HAVE_DOCSTRINGS

--- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -1,21 +1,25 @@ +import _testcapi +import collections +import datetime +import functools +import importlib +import inspect +import io +import linecache +import os +from os.path import normcase +import _pickle import re +import shutil import sys import types +import unicodedata import unittest -import inspect -import linecache -import datetime -import collections -import os -import shutil -import functools -import importlib -from os.path import normcase + try: from concurrent.futures import ThreadPoolExecutor except ImportError: ThreadPoolExecutor = None -import _testcapi from test.support import run_unittest, TESTFN, DirsOnSysPath from test.support import MISSING_C_DOCSTRINGS @@ -23,8 +27,6 @@ from test.script_helper import assert_py from test import inspect_fodder as mod from test import inspect_fodder2 as mod2 -# C module for test_findsource_binary -import unicodedata

Functions tested in this suite:

ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode,

@@ -1582,23 +1584,30 @@ class TestSignatureObject(unittest.TestC ...)) def test_signature_on_unsupported_builtins(self):

@unittest.skipIf(MISSING_C_DOCSTRINGS, "Signature information for builtins requires docstrings") def test_signature_on_builtins(self):

-

+

+

+

@@ -1611,6 +1620,41 @@ class TestSignatureObject(unittest.TestC self.assertEqual(p('sys'), sys.maxsize) self.assertEqual(p('exp'), sys.maxsize - 1)

+

+

+

+

+

+

+ +

+ def test_signature_on_non_function(self): with self.assertRaisesRegex(TypeError, 'is not a callable object'): inspect.signature(42) @@ -1985,12 +2029,6 @@ class TestSignatureObject(unittest.TestC ((('a', ..., ..., "positional_or_keyword"),), ...))

- - class Wrapped: pass Wrapped.wrapped = lambda a: None

--- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -112,11 +112,24 @@ def _check_signature(func, mock, skipfir def _copy_func_details(func, funcopy): funcopy.name = func.name funcopy.doc = func.doc

def _callable(obj):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ Release date: 2014-01-19 Core and Builtins ----------------- +- Issue #20189: Four additional builtin types (PyTypeObject,

--- a/Modules/cryptmodule.c +++ b/Modules/cryptmodule.c @@ -30,7 +30,7 @@ results for a given word. [clinic start generated code]*/ PyDoc_STRVAR(crypt_crypt__doc, -"crypt(word, salt)\n" +"crypt(module, word, salt)\n" "Hash a word with the given salt and return the hashed password.\n" "\n" "word will usually be a user's password. salt (either a random 2 or 16\n" @@ -63,7 +63,7 @@ exit: static PyObject crypt_crypt_impl(PyModuleDef module, const char word, const char salt) -/[clinic end generated code: checksum=a137540bf6862f9935fc112b8bb1d62d6dd1ad02]/ +/[clinic end generated code: checksum=dbfe26a21eb335abefe6a0bbd0a682ea22b9adc0]/ { /* On some platforms (AtheOS) crypt returns NULL for an invalid salt. Return None in that case. XXX Maybe raise an exception? */

--- a/Modules/cursesmodule.c +++ b/Modules/cursesmodule.c @@ -584,7 +584,7 @@ current settings for the window object. [clinic start generated code]*/ PyDoc_STRVAR(curses_window_addch__doc, -"addch([x, y,] ch, [attr])\n" +"addch(self, [x, y,] ch, [attr])\n" "Paint character ch at (y, x) with attributes attr.\n" "\n" " x\n" @@ -651,7 +651,7 @@ exit: 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=53d44d79791b30950972b3256bdd464f7426bf82]/ +/[clinic end generated code: checksum=f6eeada77a9ec085125f3a27e4a2095f2a4c50be]*/ { PyCursesWindowObject *cwself = (PyCursesWindowObject *)self; int coordinates_group = group_left_1;

--- a/Modules/datetimemodule.c +++ b/Modules/datetimemodule.c @@ -4159,7 +4159,7 @@ If no tz is specified, uses local timezo [clinic start generated code]*/ PyDoc_STRVAR(datetime_datetime_now__doc, -"now(tz=None)\n" +"now(type, tz=None)\n" "Returns new datetime object representing current time local to tz.\n" "\n" " tz\n" @@ -4171,10 +4171,10 @@ PyDoc_STRVAR(datetime_datetime_now__doc_ {"now", (PyCFunction)datetime_datetime_now, METH_VARARGS|METH_KEYWORDS|METH_CLASS, datetime_datetime_now__doc__}, static PyObject * -datetime_datetime_now_impl(PyTypeObject *cls, PyObject *tz); +datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz); static PyObject * -datetime_datetime_now(PyTypeObject *cls, PyObject *args, PyObject *kwargs) +datetime_datetime_now(PyTypeObject *type, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"tz", NULL}; @@ -4184,15 +4184,15 @@ datetime_datetime_now(PyTypeObject *cls, "|O:now", _keywords, &tz)) goto exit;

exit: return return_value; } static PyObject * -datetime_datetime_now_impl(PyTypeObject cls, PyObject tz) -/[clinic end generated code: checksum=ca3d26a423b3f633b260c7622e303f0915a96f7c]/ +datetime_datetime_now_impl(PyTypeObject type, PyObject tz) +/[clinic end generated code: checksum=a6d3ad2c0ab6389075289af3467f7b8eb13f5f5c]/ { PyObject *self; @@ -4202,7 +4202,7 @@ datetime_datetime_now_impl(PyTypeObject if (check_tzinfo_subclass(tz) < 0) return NULL;

--- a/Modules/dbmmodule.c +++ b/Modules/dbmmodule.c @@ -279,7 +279,7 @@ Return the value for key if present, oth [clinic start generated code]*/ PyDoc_STRVAR(dbm_dbm_get__doc, -"get(key, [default])\n" +"get(self, key, [default])\n" "Return the value for key if present, otherwise default."); #define DBM_DBM_GET_METHODDEF [](#l15.11) @@ -289,7 +289,7 @@ static PyObject * dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, int group_right_1, PyObject *default_value); static PyObject * -dbm_dbm_get(PyObject *self, PyObject *args) +dbm_dbm_get(dbmobject *dp, PyObject *args) { PyObject *return_value = NULL; const char *key; @@ -311,7 +311,7 @@ dbm_dbm_get(PyObject *self, PyObject *ar PyErr_SetString(PyExc_TypeError, "dbm.dbm.get requires 1 to 2 arguments"); goto exit; }

exit: return return_value; @@ -319,7 +319,7 @@ exit: 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=ca8bf63ec226e71d3cf390749777f7d5b7361478]/ +/[clinic end generated code: checksum=31d5180d6b36f1eafea78ec4391adf3559916379]/ { datum dbm_key, val; @@ -462,7 +462,7 @@ Return a database object. [clinic start generated code]*/ PyDoc_STRVAR(dbmopen__doc__, -"open(filename, flags='r', mode=0o666)\n" +"open(module, filename, flags='r', mode=0o666)\n" "Return a database object.\n" "\n" " filename\n" @@ -499,7 +499,7 @@ exit: static PyObject dbmopen_impl(PyModuleDef module, const char filename, const char flags, int mode) -/[clinic end generated code: checksum=fb265f75641553ccd963f84c143b35c11f9121fc]/ +/[clinic end generated code: checksum=9efae7d3c3b67a365011bf4e463e918901ba6c79]/ { int iflags;

--- a/Modules/_opcode.c +++ b/Modules/opcode.c @@ -21,7 +21,7 @@ Compute the stack effect of the opcode. [clinic start generated code]*/ PyDoc_STRVAR(opcode_stack_effect__doc, -"stack_effect(opcode, [oparg])\n" +"stack_effect(module, opcode, [oparg])\n" "Compute the stack effect of the opcode."); #define _OPCODE_STACK_EFFECT_METHODDEF [](#l16.11) @@ -64,7 +64,7 @@ exit: static int _opcode_stack_effect_impl(PyModuleDef module, int opcode, int group_right_1, int oparg) -/[clinic end generated code: checksum=58fb4f1b174fc92f783dc945ca712fb752a6c283]/ +/[clinic end generated code: checksum=4689140ffda2494a123ea2593fb63445fb039774]*/ { int effect; if (HAS_ARG(opcode)) {

--- a/Modules/_pickle.c +++ b/Modules/pickle.c @@ -3889,7 +3889,7 @@ re-using picklers. [clinic start generated code]*/ PyDoc_STRVAR(pickle_Pickler_clear_memo__doc, -"clear_memo()\n" +"clear_memo(self)\n" "Clears the pickler's "memo".\n" "\n" "The memo is the data structure that remembers which objects the\n" @@ -3904,14 +3904,14 @@ static PyObject * _pickle_Pickler_clear_memo_impl(PicklerObject *self); static PyObject * -_pickle_Pickler_clear_memo(PyObject *self, PyObject *Py_UNUSED(ignored)) -{

+_pickle_Pickler_clear_memo(PicklerObject *self, PyObject *Py_UNUSED(ignored)) +{

} static PyObject _pickle_Pickler_clear_memo_impl(PicklerObject self) -/[clinic end generated code: checksum=015cc3c5befea86cb08b9396938477bebbea4157]/ +/[clinic end generated code: checksum=17b1165d8dcae5a2e90b1703bf5cbbfc26114c5a]/ { if (self->memo) PyMemoTable_Clear(self->memo); @@ -3931,7 +3931,7 @@ Write a pickled representation of the gi [clinic start generated code]/ PyDoc_STRVAR(pickle_Pickler_dump__doc_, -"dump(obj)\n" +"dump(self, obj)\n" "Write a pickled representation of the given object to the open file."); #define PICKLE_PICKLER_DUMP_METHODDEF [](#l17.39) @@ -3939,7 +3939,7 @@ PyDoc_STRVAR(pickle_Pickler_dump__doc static PyObject _pickle_Pickler_dump(PicklerObject self, PyObject obj) -/[clinic end generated code: checksum=b72a69ec98737fabf66dae7c5a3210178bdbd3e6]/ +/[clinic end generated code: checksum=36db7f67c8bc05ca6f17b8ab57c54d64bfd0539e]/ { /* Check whether the Pickler was initialized correctly (issue3664). Developers often forget to call init() in their subclasses, which @@ -4077,7 +4077,7 @@ static int int fix_imports = 1; if (!PyArg_ParseTupleAndKeywords(args, kwargs,

#define _PICKLE_PICKLERMEMOPROXY_CLEAR_METHODDEF [](#l17.75) @@ -4174,14 +4174,14 @@ static PyObject * _pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self); static PyObject * -_pickle_PicklerMemoProxy_clear(PyObject *self, PyObject *Py_UNUSED(ignored)) -{

+_pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) +{

} static PyObject _pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject self) -/[clinic end generated code: checksum=bf8dd8c8688d0c0f7a2e59a804c47375b740f2f0]/ +/[clinic end generated code: checksum=fb4a5ba40918b3eccc9bc1e9d6875cb2737127a9]/ { if (self->pickler->memo) PyMemoTable_Clear(self->pickler->memo); @@ -4197,7 +4197,7 @@ Copy the memo to a new object. [clinic start generated code]*/ PyDoc_STRVAR(pickle_PicklerMemoProxy_copy__doc_, -"copy()\n" +"copy(self)\n" "Copy the memo to a new object."); #define _PICKLE_PICKLERMEMOPROXY_COPY_METHODDEF [](#l17.103) @@ -4207,14 +4207,14 @@ static PyObject * _pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self); static PyObject * -_pickle_PicklerMemoProxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) -{

+_pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) +{

} static PyObject _pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject self) -/[clinic end generated code: checksum=72d46879dc658adbd3d28b5c82dd8dcfa6b9b124]/ +/[clinic end generated code: checksum=3d27d3005725f1828c9a92a38197811c54c64abb]/ { Py_ssize_t i; PyMemoTable memo; @@ -4260,7 +4260,7 @@ Implement pickle support. [clinic start generated code]/ PyDoc_STRVAR(pickle_PicklerMemoProxy___reduce____doc_, -"reduce()\n" +"reduce(self)\n" "Implement pickle support."); #define _PICKLE_PICKLERMEMOPROXY___REDUCE___METHODDEF [](#l17.131) @@ -4270,14 +4270,14 @@ static PyObject * pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self); static PyObject * -pickle_PicklerMemoProxy___reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) -{

+pickle_PicklerMemoProxy___reduce_(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) +{

} static PyObject _pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject self) -/[clinic end generated code: checksum=aad71c4d81d1ed8bf0d32362dd80a29b9f3b0d03]/ +/[clinic end generated code: checksum=2682cf8a3a5027def6328419001b086b047d47c8]/ { PyObject reduce_value, dict_args; PyObject contents = _pickle_PicklerMemoProxy_copy_impl(self); @@ -6299,7 +6299,7 @@ specified therein. [clinic start generated code]/ PyDoc_STRVAR(pickle_Unpickler_load__doc_, -"load()\n" +"load(self)\n" "Load a pickle.\n" "\n" "Read a pickled object representation from the open file object given\n" @@ -6320,7 +6320,7 @@ static PyObject static PyObject _pickle_Unpickler_load_impl(PyObject self) -/[clinic end generated code: checksum=9477099fe6a90748c13ff1a6dd92ba7ab7a89602]/ +/[clinic end generated code: checksum=fb1119422c5e03045d690d1cd6c457f1ca4c585d]/ { UnpicklerObject unpickler = (UnpicklerObject)self; @@ -6363,7 +6363,7 @@ needed. Both arguments passed are str o [clinic start generated code]/ PyDoc_STRVAR(pickle_Unpickler_find_class__doc_, -"find_class(module_name, global_name)\n" +"find_class(self, module_name, global_name)\n" "Return an object from a specified module.\n" "\n" "If necessary, the module will be imported. Subclasses may override\n" @@ -6380,7 +6380,7 @@ static PyObject * _pickle_Unpickler_find_class_impl(UnpicklerObject *self, PyObject *module_name, PyObject *global_name); static PyObject * -_pickle_Unpickler_find_class(PyObject *self, PyObject *args) +_pickle_Unpickler_find_class(UnpicklerObject *self, PyObject *args) { PyObject *return_value = NULL; PyObject *module_name; @@ -6390,7 +6390,7 @@ static PyObject * 2, 2, &module_name, &global_name)) goto exit;

exit: return return_value; @@ -6398,7 +6398,7 @@ exit: static PyObject _pickle_Unpickler_find_class_impl(UnpicklerObject self, PyObject module_name, PyObject global_name) -/[clinic end generated code: checksum=15ed4836fd5860425fff9ea7855d4f1f4413c170]/ +/[clinic end generated code: checksum=2b8d5398787c8ac7ea5d45f644433169e441003b]/ { PyObject *global; PyObject *modules_dict; @@ -6617,7 +6617,7 @@ static int const char *errors = "strict"; if (!PyArg_ParseTupleAndKeywords(args, kwargs,

#define _PICKLE_UNPICKLERMEMOPROXY_CLEAR_METHODDEF [](#l17.231) @@ -6708,14 +6708,14 @@ static PyObject * _pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self); static PyObject * -_pickle_UnpicklerMemoProxy_clear(PyObject *self, PyObject *Py_UNUSED(ignored)) -{

+_pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) +{

} static PyObject _pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject self) -/[clinic end generated code: checksum=07adecee2181e5e268b2ff184360b1d88ad947f2]/ +/[clinic end generated code: checksum=32f6ee47e44405dd587f768f3690d47947bb5a8e]/ { _Unpickler_MemoCleanup(self->unpickler); self->unpickler->memo = Unpickler_NewMemo(self->unpickler->memo_size); @@ -6733,7 +6733,7 @@ Copy the memo to a new object. [clinic start generated code]*/ PyDoc_STRVAR(pickle_UnpicklerMemoProxy_copy__doc, -"copy()\n" +"copy(self)\n" "Copy the memo to a new object."); #define _PICKLE_UNPICKLERMEMOPROXY_COPY_METHODDEF [](#l17.259) @@ -6743,14 +6743,14 @@ static PyObject * _pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self); static PyObject * -_pickle_UnpicklerMemoProxy_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) -{

+_pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) +{

} static PyObject _pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject self) -/[clinic end generated code: checksum=47b9f0cc12c5a54004252e1b4916822cdfa8a881]/ +/[clinic end generated code: checksum=ac3da80efc3b2548aa8b5c5358d0e82e615fce1d]/ { Py_ssize_t i; PyObject new_memo = PyDict_New(); @@ -6789,7 +6789,7 @@ Implement pickling support. [clinic start generated code]/ PyDoc_STRVAR(pickle_UnpicklerMemoProxy___reduce____doc_, -"reduce()\n" +"reduce(self)\n" "Implement pickling support."); #define _PICKLE_UNPICKLERMEMOPROXY___REDUCE___METHODDEF [](#l17.287) @@ -6799,14 +6799,14 @@ static PyObject * pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self); static PyObject * -pickle_UnpicklerMemoProxy___reduce(PyObject *self, PyObject *Py_UNUSED(ignored)) -{

+pickle_UnpicklerMemoProxy___reduce_(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored)) +{

} static PyObject _pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject self) -/[clinic end generated code: checksum=2f061bb9ecd9ee8500184c135148a131c46a3b88]/ +/[clinic end generated code: checksum=2373102b7c87d99ba4c4a56b6813d2c84dd61865]/ { PyObject *reduce_value; PyObject constructor_args; @@ -7115,7 +7115,7 @@ 2, so that the pickle data stream is rea [clinic start generated code]/ PyDoc_STRVAR(pickle_dump__doc_, -"dump(obj, file, protocol=None, *, fix_imports=True)\n" +"dump(module, obj, file, protocol=None, *, fix_imports=True)\n" "Write a pickled representation of obj to the open file object file.\n" "\n" "This is equivalent to Pickler(file, protocol).dump(obj), but may\n" @@ -7166,7 +7166,7 @@ exit: static PyObject * _pickle_dump_impl(PyModuleDef module, PyObject obj, PyObject file, PyObject protocol, int fix_imports) -/[clinic end generated code: checksum=eb5c23e64da34477178230b704d2cc9c6b6650ea]/ +/[clinic end generated code: checksum=1d4ff873e13eb840ff275d716d8d4c5554af087c]/ { PicklerObject pickler = _Pickler_New(); @@ -7218,7 +7218,7 @@ Python 2, so that the pickle data stream [clinic start generated code]/ PyDoc_STRVAR(pickle_dumps__doc_, -"dumps(obj, protocol=None, *, fix_imports=True)\n" +"dumps(module, obj, protocol=None, *, fix_imports=True)\n" "Return the pickled representation of the object as a bytes object.\n" "\n" "The optional protocol argument tells the pickler to use the given\n" @@ -7260,7 +7260,7 @@ exit: static PyObject _pickle_dumps_impl(PyModuleDef module, PyObject obj, PyObject protocol, int fix_imports) -/[clinic end generated code: checksum=e9b915d61202a9692cb6c6718db74fe54fc9c4d1]/ +/[clinic end generated code: checksum=9c6c0291ef2d2b0856b7d4caecdcb7bad13a23b3]/ { PyObject *result; PicklerObject pickler = _Pickler_New(); @@ -7319,7 +7319,7 @@ string instances as bytes objects. [clinic start generated code]/ PyDoc_STRVAR(pickle_load__doc_, -"load(file, *, fix_imports=True, encoding='ASCII', errors='strict')\n" +"load(module, file, *, fix_imports=True, encoding='ASCII', errors='strict')\n" "Read and return an object from the pickle data stored in a file.\n" "\n" "This is equivalent to Unpickler(file).load(), but may be more\n" @@ -7372,7 +7372,7 @@ exit: static PyObject * _pickle_load_impl(PyModuleDef module, PyObject file, int fix_imports, const char encoding, const char errors) -/[clinic end generated code: checksum=b41f06970e57acf2fd602e4b7f88e3f3e1e53087]/ +/[clinic end generated code: checksum=2b5b7e5e3a836cf1c53377ce9274a84a8bceef67]/ { PyObject *result; UnpicklerObject unpickler = _Unpickler_New(); @@ -7424,7 +7424,7 @@ string instances as bytes objects. [clinic start generated code]/ PyDoc_STRVAR(pickle_loads__doc_, -"loads(data, *, fix_imports=True, encoding='ASCII', errors='strict')\n" +"loads(module, data, *, fix_imports=True, encoding='ASCII', errors='strict')\n" "Read and return an object from the given pickle data.\n" "\n" "The protocol version of the pickle is detected automatically, so no\n" @@ -7468,7 +7468,7 @@ exit: static PyObject * _pickle_loads_impl(PyModuleDef module, PyObject data, int fix_imports, const char encoding, const char errors) -/[clinic end generated code: checksum=0663de43aca6c21508a777e29d98c9c3a6e7f72d]/ +/[clinic end generated code: checksum=7b21a75997c8f6636e4bf48c663b28f2bfd4eb6a]/ { PyObject *result; UnpicklerObject *unpickler = _Unpickler_New();

--- a/Modules/sre.c +++ b/Modules/sre.c @@ -541,7 +541,7 @@ Matches zero or more characters at the b [clinic start generated code]*/ PyDoc_STRVAR(pattern_match__doc, -"match(pattern, pos=0, endpos=sys.maxsize)\n" +"match(self, pattern, pos=0, endpos=sys.maxsize)\n" "Matches zero or more characters at the beginning of the string."); #define PATTERN_MATCH_METHODDEF [](#l18.11) @@ -551,7 +551,7 @@ static PyObject * pattern_match_impl(PatternObject *self, PyObject *pattern, Py_ssize_t pos, Py_ssize_t endpos); static PyObject * -pattern_match(PyObject *self, PyObject *args, PyObject *kwargs) +pattern_match(PatternObject *self, PyObject *args, PyObject *kwargs) { PyObject *return_value = NULL; static char *_keywords[] = {"pattern", "pos", "endpos", NULL}; @@ -563,7 +563,7 @@ pattern_match(PyObject *self, PyObject * "O|nn:match", _keywords, &pattern, &pos, &endpos)) goto exit;

exit: return return_value; @@ -571,7 +571,7 @@ exit: static PyObject pattern_match_impl(PatternObject self, PyObject pattern, Py_ssize_t pos, Py_ssize_t endpos) -/[clinic end generated code: checksum=63e59c5f3019efe6c1f3acdec42b2d3595e14a09]/ +/[clinic end generated code: checksum=4a3865d13638cb7c13dcae1fe58c1a9c35071998]*/ { SRE_STATE state; Py_ssize_t status;

--- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2851,18 +2851,18 @@ PyDoc_STRVAR(docstring_no_signature, ); PyDoc_STRVAR(docstring_with_invalid_signature, -"docstring_with_invalid_signature (boo)\n" +"docstring_with_invalid_signature (module, boo)\n" "\n" "This docstring has an invalid signature." ); PyDoc_STRVAR(docstring_with_signature, -"docstring_with_signature(sig)\n" +"docstring_with_signature(module, sig)\n" "This docstring has a valid signature." ); PyDoc_STRVAR(docstring_with_signature_and_extra_newlines, -"docstring_with_signature_and_extra_newlines(parameter)\n" +"docstring_with_signature_and_extra_newlines(module, parameter)\n" "\n" "\n" "\n" @@ -2870,7 +2870,7 @@ PyDoc_STRVAR(docstring_with_signature_an ); PyDoc_STRVAR(docstring_with_signature_with_defaults, -"docstring_with_signature_with_defaults(s='avocado', b=b'bytes', d=3.14, i=35, n=None, t=True, f=False, local=the_number_three, sys=sys.maxsize, exp=sys.maxsize - 1)\n" +"docstring_with_signature_with_defaults(module, s='avocado', b=b'bytes', d=3.14, i=35, n=None, t=True, f=False, local=the_number_three, sys=sys.maxsize, exp=sys.maxsize - 1)\n" "\n" "\n" "\n"

--- a/Modules/_weakref.c +++ b/Modules/weakref.c @@ -20,7 +20,7 @@ Return the number of weak references to [clinic start generated code]*/ PyDoc_STRVAR(weakref_getweakrefcount__doc, -"getweakrefcount(object)\n" +"getweakrefcount(module, object)\n" "Return the number of weak references to 'object'."); #define _WEAKREF_GETWEAKREFCOUNT_METHODDEF [](#l20.11) @@ -46,7 +46,7 @@ exit: static Py_ssize_t _weakref_getweakrefcount_impl(PyModuleDef module, PyObject object) -/[clinic end generated code: checksum=744fa73ba68c0ee89567e9cb9bea11863270d516]/ +/[clinic end generated code: checksum=dd8ba0730babf263d3db78d260ea7eacf6eb3735]/ { PyWeakReference **list;

--- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -2430,7 +2430,7 @@ It's an error to use dir_fd or follow_sy [clinic start generated code]/ PyDoc_STRVAR(os_stat__doc__, -"stat(path, , dir_fd=None, follow_symlinks=True)\n" +"stat(module, path, , dir_fd=None, follow_symlinks=True)\n" "Perform a stat system call on the given path.\n" "\n" " path\n" @@ -2481,7 +2481,7 @@ exit: static PyObject os_stat_impl(PyModuleDef module, path_t path, int dir_fd, int follow_symlinks) -/[clinic end generated code: checksum=85a71ad602e89f8e280118da976f70cd2f9abdf1]/ +/[clinic end generated code: checksum=09cc91b4947f9e3b9335c8be998bb7c56f7f8b40]/ { return posix_do_stat("stat", path, dir_fd, follow_symlinks); } @@ -2562,7 +2562,7 @@ Note that most operations will use the e [clinic start generated code]/ PyDoc_STRVAR(os_access__doc__, -"access(path, mode, , dir_fd=None, effective_ids=False, follow_symlinks=True)\n" +"access(module, path, mode, , dir_fd=None, effective_ids=False, follow_symlinks=True)\n" "Use the real uid/gid to test for access to a path.\n" "\n" " path\n" @@ -2622,7 +2622,7 @@ exit: static PyObject os_access_impl(PyModuleDef module, path_t path, int mode, int dir_fd, int effective_ids, int follow_symlinks) -/[clinic end generated code: checksum=636e835c36562a2fc11acab75314634127fdf769]/ +/[clinic end generated code: checksum=6483a51e1fee83da4f8e41cbc8054a701cfed1c5]/ { PyObject return_value = NULL; @@ -2718,7 +2718,7 @@ Return the name of the terminal device c [clinic start generated code]/ PyDoc_STRVAR(os_ttyname__doc__, -"ttyname(fd)\n" +"ttyname(module, fd)\n" "Return the name of the terminal device connected to 'fd'.\n" "\n" " fd\n" @@ -2752,7 +2752,7 @@ exit: static char os_ttyname_impl(PyModuleDef module, int fd) -/[clinic end generated code: checksum=0f368134dc0a7f21f25185e2e6bacf7675fb473a]/ +/[clinic end generated code: checksum=11bbb8b7969155f54bb8a1ec35ac1ebdfd4b0fec]/ { char *ret;

--- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -129,7 +129,7 @@ not given, ValueError is raised. [clinic start generated code]*/ PyDoc_STRVAR(unicodedata_UCD_decimal__doc__, -"decimal(unichr, default=None)\n" +"decimal(self, unichr, default=None)\n" "Converts a Unicode character into its equivalent decimal value.\n" "\n" "Returns the decimal value assigned to the Unicode character unichr\n" @@ -161,7 +161,7 @@ exit: static PyObject unicodedata_UCD_decimal_impl(PyObject self, PyUnicodeObject unichr, PyObject default_value) -/[clinic end generated code: checksum=73edde0e9cd5913ea174c4fa81504369761b7426]/ +/[clinic end generated code: checksum=01826b179d497d8fd3842c56679ecbd4faddaa95]/ { PyUnicodeObject *v = (PyUnicodeObject *)unichr; int have_old = 0;

--- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -180,7 +180,7 @@ Returns compressed string. [clinic start generated code]/ PyDoc_STRVAR(zlib_compress__doc__, -"compress(bytes, [level])\n" +"compress(module, bytes, [level])\n" "Returns compressed string.\n" "\n" " bytes\n" @@ -228,7 +228,7 @@ exit: static PyObject zlib_compress_impl(PyModuleDef module, Py_buffer bytes, int group_right_1, int level) -/[clinic end generated code: checksum=74648f97e6b9d3cc9cd568d47262d462bded7ed0]/ +/[clinic end generated code: checksum=ce8d4c0a17ecd79c3ffcc032dcdf8ac6830ded1e]/ { PyObject *ReturnVal = NULL; Byte *input, output = NULL; @@ -766,7 +766,7 @@ Call the flush() method to clear these b [clinic start generated code]/ PyDoc_STRVAR(zlib_Decompress_decompress__doc__, -"decompress(data, max_length=0)\n" +"decompress(self, data, max_length=0)\n" "Return a string containing the decompressed version of the data.\n" "\n" " data\n" @@ -787,7 +787,7 @@ static PyObject * zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data, unsigned int max_length); static PyObject * -zlib_Decompress_decompress(PyObject *self, PyObject *args) +zlib_Decompress_decompress(compobject *self, PyObject *args) { PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; @@ -797,7 +797,7 @@ zlib_Decompress_decompress(PyObject sel "y|O&:decompress", &data, uint_converter, &max_length)) goto exit;

exit: /* Cleanup for data / @@ -809,7 +809,7 @@ exit: static PyObject zlib_Decompress_decompress_impl(compobject self, Py_buffer data, unsigned int max_length) -/[clinic end generated code: checksum=e0058024c4a97b411d2e2197791b89fde175f76f]/ +/[clinic end generated code: checksum=b7fd2e3b23430f57f5a84817189575bc46464901]/ { int err; unsigned int old_length, length = DEFAULTALLOC; @@ -1036,7 +1036,7 @@ Return a copy of the compression object. [clinic start generated code]*/ PyDoc_STRVAR(zlib_Compress_copy__doc__, -"copy()\n" +"copy(self)\n" "Return a copy of the compression object."); #define ZLIB_COMPRESS_COPY_METHODDEF [](#l23.65) @@ -1046,14 +1046,14 @@ static PyObject * zlib_Compress_copy_impl(compobject *self); static PyObject * -zlib_Compress_copy(PyObject *self, PyObject *Py_UNUSED(ignored)) +zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored)) {

} static PyObject zlib_Compress_copy_impl(compobject self) -/[clinic end generated code: checksum=d57a7911deb7940e85a8d7e65af20b6e2df69000]/ +/[clinic end generated code: checksum=7aa841ad51297eb83250f511a76872e88fdc737e]/ { compobject *retval = NULL; int err;

--- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -353,11 +353,17 @@ wrapperdescr_call(PyWrapperDescrObject * static PyObject * method_get_doc(PyMethodDescrObject *descr, void *closure) {

+} + +static PyObject * +method_get_text_signature(PyMethodDescrObject *descr, void *closure) +{

} static PyObject * @@ -425,6 +431,7 @@ static PyMemberDef descr_members[] = { static PyGetSetDef method_getset[] = { {"doc", (getter)method_get_doc}, {"qualname", (getter)descr_get_qualname},

+} + +static PyObject * +wrapperdescr_get_text_signature(PyWrapperDescrObject *descr, void *closure) +{

} static PyGetSetDef wrapperdescr_getset[] = { {"doc", (getter)wrapperdescr_get_doc}, {"qualname", (getter)descr_get_qualname},

static PyObject * -wrapper_doc(wrapperobject *wp) +wrapper_doc(wrapperobject *wp, void *closure) {

+}

+static PyObject * +wrapper_text_signature(wrapperobject *wp, void *closure) +{

} static PyObject * @@ -1167,6 +1183,7 @@ static PyGetSetDef wrapper_getsets[] = { {"name", (getter)wrapper_name}, {"qualname", (getter)wrapper_qualname}, {"doc", (getter)wrapper_doc},

--- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1691,37 +1691,71 @@ dict_items(PyDictObject mp) return v; } +/[clinic input] +@classmethod +dict.fromkeys +

+ +Returns a new dict with keys from iterable and values equal to value. +[clinic start generated code]*/ + +PyDoc_STRVAR(dict_fromkeys__doc__, +"fromkeys(type, iterable, value=None)\n" +"Returns a new dict with keys from iterable and values equal to value."); + +#define DICT_FROMKEYS_METHODDEF [](#l25.22)

+ static PyObject * -dict_fromkeys(PyObject *cls, PyObject *args) +dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, PyObject *value); + +static PyObject * +dict_fromkeys(PyTypeObject *type, PyObject *args) {

+ +exit:

+} + +static PyObject * +dict_fromkeys_impl(PyTypeObject *type, PyObject iterable, PyObject value) +/[clinic end generated code: checksum=008269e1774a379b356841548c04061fd78a9542]/ +{ PyObject it; / iter(seq) */ PyObject *key; PyObject *d; int status;

-

if (PyDict_CheckExact(d) && ((PyDictObject *)d)->ma_used == 0) {

@@ -1729,18 +1763,18 @@ dict_fromkeys(PyObject *cls, PyObject *a } return d; }

@@ -1750,7 +1784,7 @@ dict_fromkeys(PyObject *cls, PyObject *a } }

@@ -2176,7 +2210,7 @@ True if D has a key k, else False. [clinic start generated code]/ PyDoc_STRVAR(dict___contains____doc__, -"contains(key)\n" +"contains(self, key)\n" "True if D has a key k, else False."); #define DICT___CONTAINS___METHODDEF [](#l25.123) @@ -2184,7 +2218,7 @@ PyDoc_STRVAR(dict___contains____doc__, static PyObject dict___contains__(PyObject self, PyObject key) -/[clinic end generated code: checksum=402ddb624ba1e4db764bfdfbbee6c1c59d1a11fa]/ +/[clinic end generated code: checksum=c4f85a39baac4776c4275ad5f072f7732c5f0806]/ { register PyDictObject *mp = (PyDictObject *)self; Py_hash_t hash; @@ -2496,10 +2530,6 @@ If E is present and has a .keys() method If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v\n[](#l25.134) In either case, this is followed by: for k in F: D[k] = F[k]"); -PyDoc_STRVAR(fromkeys__doc__, -"dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.\n[](#l25.138) -v defaults to None."); - PyDoc_STRVAR(clear__doc__, "D.clear() -> None. Remove all items from D."); @@ -2540,8 +2570,7 @@ static PyMethodDef mapp_methods[] = { values__doc__}, {"update", (PyCFunction)dict_update, METH_VARARGS | METH_KEYWORDS, update__doc__},

--- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -179,75 +179,20 @@ static PyMethodDef meth_methods[] = { {NULL, NULL} }; -/*

-} - -/*

-} - -static const char *skip_eols(const char *trace) -{

-} - static PyObject * meth_get__text_signature__(PyCFunctionObject *m, void *closure) {

-

-

} static PyObject * meth_get__doc__(PyCFunctionObject *m, void *closure) {

-

-

} static PyObject *

--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -54,6 +54,83 @@ static unsigned int next_version_tag = 0 static PyObject * slot_tp_new(PyTypeObject *type, PyObject *args, PyObject kwds); +/

+} + +/*

+} + +static const char * +skip_eols(const char *trace) +{

+} + +static const char * +_PyType_DocWithoutSignature(const char *name, const char *internal_doc) +{

+

+} + +PyObject * +_PyType_GetDocFromInternalDoc(const char *name, const char *internal_doc) +{

+

+

+} + +PyObject * +_PyType_GetTextSignatureFromInternalDoc(const char *name, const char *internal_doc) +{

+

+

+} + unsigned int PyType_ClearCache(void) { @@ -628,8 +705,11 @@ static PyObject * type_get_doc(PyTypeObject *type, void *context) { PyObject *result;

@@ -645,6 +725,14 @@ type_get_doc(PyTypeObject *type, void *c return result; } +static PyObject * +type_get_text_signature(PyTypeObject *type, void *context) +{

+} + static int type_set_doc(PyTypeObject *type, PyObject *value, void *context) { @@ -691,6 +779,7 @@ static PyGetSetDef type_getsets[] = { (setter)type_set_abstractmethods, NULL}, {"dict", (getter)type_dict, NULL, NULL}, {"doc", (getter)type_get_doc, (setter)type_set_doc, NULL},

@@ -3788,7 +3880,7 @@ reduce_4(PyObject *obj) Py_DECREF(state); Py_DECREF(listitems); Py_DECREF(dictitems);

} static PyObject * @@ -3813,7 +3905,7 @@ reduce_2(PyObject *obj) } else if (kwargs != NULL) { if (PyDict_Size(kwargs) > 0) {

@@ -4103,8 +4195,8 @@ PyTypeObject PyBaseObject_Type = { PyObject_GenericGetAttr, /* tp_getattro / PyObject_GenericSetAttr, / tp_setattro / 0, / tp_as_buffer */

@@ -6005,22 +6098,22 @@ typedef struct wrapperbase slotdef; ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, DOC) #define UNSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) [](#l27.200) ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, [](#l27.201)

#define IBSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) [](#l27.204) ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, [](#l27.205)

#define BINSLOT(NAME, SLOT, FUNCTION, DOC) [](#l27.208) ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_l, [](#l27.209)

#define RBINSLOT(NAME, SLOT, FUNCTION, DOC) [](#l27.212) ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_r, [](#l27.213)

#define BINSLOTNOTINFIX(NAME, SLOT, FUNCTION, DOC) [](#l27.216) ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_l, [](#l27.217)

#define RBINSLOTNOTINFIX(NAME, SLOT, FUNCTION, DOC) [](#l27.220) ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_r, [](#l27.221)

static slotdef slotdefs[] = { TPSLOT("getattribute", tp_getattr, NULL, NULL, ""), @@ -6028,80 +6121,85 @@ static slotdef slotdefs[] = { TPSLOT("setattr", tp_setattr, NULL, NULL, ""), TPSLOT("delattr", tp_setattr, NULL, NULL, ""), TPSLOT("repr", tp_repr, slot_tp_repr, wrap_unaryfunc,

-

SQSLOT("len", sq_length, slot_sq_length, wrap_lenfunc,

{NULL} };

--- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -12900,7 +12900,7 @@ PyDoc_STRVAR(unicode_maketrans__doc__, {"maketrans", (PyCFunction)unicode_maketrans, METH_VARARGS|METH_STATIC, unicode_maketrans__doc__}, static PyObject * -unicode_maketrans_impl(void *null, PyObject *x, PyObject *y, PyObject *z); +unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z); static PyObject * unicode_maketrans(void *null, PyObject *args) @@ -12914,15 +12914,15 @@ unicode_maketrans(void *null, PyObject * "O|UU:maketrans", &x, &y, &z)) goto exit;

exit: return return_value; } static PyObject * -unicode_maketrans_impl(void *null, PyObject *x, PyObject y, PyObject z) -/[clinic end generated code: checksum=7f76f414a0dfd0c614e0d4717872eeb520516da7]/ +unicode_maketrans_impl(PyObject *x, PyObject y, PyObject z) +/[clinic end generated code: checksum=90a3de8c494b304687e1e0d7e5fa8ba78eac6533]/ { PyObject *new = NULL, *key, *value; Py_ssize_t i = 0;

--- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1325,7 +1325,7 @@ builtin_len(PyObject *self, PyObject *v) } PyDoc_STRVAR(len_doc, -"len(object) -> integer\n[](#l29.7) +"len(module, object)\n[](#l29.8) \n[](#l29.9) Return the number of items of a sequence or mapping.");

--- a/Python/import.c +++ b/Python/import.c @@ -232,7 +232,7 @@ On platforms without threads, return Fal [clinic start generated code]/ PyDoc_STRVAR(imp_lock_held__doc_, -"lock_held()\n" +"lock_held(module)\n" "Return True if the import lock is currently held, else False.\n" "\n" "On platforms without threads, return False."); @@ -251,7 +251,7 @@ static PyObject static PyObject _imp_lock_held_impl(PyModuleDef module) -/[clinic end generated code: checksum=ede1cafb78eb22e3009602f684c8b780e2b82d62]/ +/[clinic end generated code: checksum=17172a9917d389dd1564e2108fec34d23aecb6c2]/ { #ifdef WITH_THREAD return PyBool_FromLong(import_lock_thread != -1); @@ -270,7 +270,7 @@ modules. On platforms without threads, t [clinic start generated code]/ PyDoc_STRVAR(imp_acquire_lock__doc_, -"acquire_lock()\n" +"acquire_lock(module)\n" "Acquires the interpreter's import lock for the current thread.\n" "\n" "This lock should be used by import hooks to ensure thread-safety when importing\n" @@ -290,7 +290,7 @@ static PyObject static PyObject _imp_acquire_lock_impl(PyModuleDef module) -/[clinic end generated code: checksum=5b520b2416c5954a7cf0ed30955d68abe20b5868]/ +/[clinic end generated code: checksum=20db30e18f6b8758386fe06907edb3f8e43080d7]/ { #ifdef WITH_THREAD PyImport_AcquireLock(); @@ -308,7 +308,7 @@ On platforms without threads, this funct [clinic start generated code]*/ PyDoc_STRVAR(imp_release_lock__doc, -"release_lock()\n" +"release_lock(module)\n" "Release the interpreter's import lock.\n" "\n" "On platforms without threads, this function does nothing."); @@ -327,7 +327,7 @@ static PyObject static PyObject _imp_release_lock_impl(PyModuleDef module) -/[clinic end generated code: checksum=efcd9d2923294c04371596e7f6d66a706d43fcac]/ +/[clinic end generated code: checksum=17749fd7752d2c392447a1f83c5d371f54d7ebd3]/ { #ifdef WITH_THREAD if (_PyImport_ReleaseLock() < 0) { @@ -927,7 +927,7 @@ Changes code.co_filename to specify the [clinic start generated code]/ PyDoc_STRVAR(imp__fix_co_filename__doc_, -"_fix_co_filename(code, path)\n" +"_fix_co_filename(module, code, path)\n" "Changes code.co_filename to specify the passed-in file path.\n" "\n" " code\n" @@ -960,7 +960,7 @@ exit: static PyObject _imp__fix_co_filename_impl(PyModuleDef module, PyCodeObject code, PyObject path) -/[clinic end generated code: checksum=4f55bad308072b30ad1921068fc4ce85bd2b39bf]/ +/[clinic end generated code: checksum=d32cf2b2e0480c714f909921cc9e55d763b39dd5]/ { update_compiled_module(code, path); @@ -1823,7 +1823,7 @@ Returns the list of file suffixes used t [clinic start generated code]/ PyDoc_STRVAR(imp_extension_suffixes__doc_, -"extension_suffixes()\n" +"extension_suffixes(module)\n" "Returns the list of file suffixes used to identify extension modules."); #define _IMP_EXTENSION_SUFFIXES_METHODDEF [](#l30.83) @@ -1840,7 +1840,7 @@ static PyObject static PyObject _imp_extension_suffixes_impl(PyModuleDef module) -/[clinic end generated code: checksum=82fb35d8429a429a4dc80c84b45b1aad73ff1de7]/ +/[clinic end generated code: checksum=625c8f11a5bbd4b85373f0a54f7f3ef19c55beb4]/ { PyObject list; const char suffix; @@ -1878,7 +1878,7 @@ Initializes a built-in module. [clinic start generated code]/ PyDoc_STRVAR(imp_init_builtin__doc_, -"init_builtin(name)\n" +"init_builtin(module, name)\n" "Initializes a built-in module."); #define _IMP_INIT_BUILTIN_METHODDEF [](#l30.101) @@ -1905,7 +1905,7 @@ exit: static PyObject _imp_init_builtin_impl(PyModuleDef module, PyObject name) -/[clinic end generated code: checksum=59239206e5b2fb59358066e72fd0e72e55a7baf5]/ +/[clinic end generated code: checksum=a4e4805a523757cd3ddfeec6e5b16740678fed6a]/ { int ret; PyObject m; @@ -1932,7 +1932,7 @@ Initializes a frozen module. [clinic start generated code]/ PyDoc_STRVAR(imp_init_frozen__doc_, -"init_frozen(name)\n" +"init_frozen(module, name)\n" "Initializes a frozen module."); #define _IMP_INIT_FROZEN_METHODDEF [](#l30.119) @@ -1959,7 +1959,7 @@ exit: static PyObject _imp_init_frozen_impl(PyModuleDef module, PyObject name) -/[clinic end generated code: checksum=503fcc3de9961263e4d9484259af357a7d287a0b]/ +/[clinic end generated code: checksum=2a58c119dd3e121cf5a9924f936cfd7b40253c12]/ { int ret; PyObject m; @@ -1986,7 +1986,7 @@ Create a code object for a frozen module [clinic start generated code]/ PyDoc_STRVAR(imp_get_frozen_object__doc_, -"get_frozen_object(name)\n" +"get_frozen_object(module, name)\n" "Create a code object for a frozen module."); #define _IMP_GET_FROZEN_OBJECT_METHODDEF [](#l30.137) @@ -2013,7 +2013,7 @@ exit: static PyObject _imp_get_frozen_object_impl(PyModuleDef module, PyObject name) -/[clinic end generated code: checksum=7a6423a4daf139496b9a394ff3ac6130089d1cba]/ +/[clinic end generated code: checksum=94c9108b58dda80d187fef21275a009bd0f91e96]/ { return get_frozen_object(name); } @@ -2028,7 +2028,7 @@ Returns True if the module name is of a [clinic start generated code]/ PyDoc_STRVAR(imp_is_frozen_package__doc_, -"is_frozen_package(name)\n" +"is_frozen_package(module, name)\n" "Returns True if the module name is of a frozen package."); #define _IMP_IS_FROZEN_PACKAGE_METHODDEF [](#l30.155) @@ -2055,7 +2055,7 @@ exit: static PyObject _imp_is_frozen_package_impl(PyModuleDef module, PyObject name) -/[clinic end generated code: checksum=dc7e361ea30b6945b8bbe7266d7b9a5ea433b510]/ +/[clinic end generated code: checksum=17a342b94dbe859cdfc361bc8a6bc1b3cb163364]/ { return is_frozen_package(name); } @@ -2070,7 +2070,7 @@ Returns True if the module name correspo [clinic start generated code]/ PyDoc_STRVAR(imp_is_builtin__doc_, -"is_builtin(name)\n" +"is_builtin(module, name)\n" "Returns True if the module name corresponds to a built-in module."); #define _IMP_IS_BUILTIN_METHODDEF [](#l30.173) @@ -2097,7 +2097,7 @@ exit: static PyObject _imp_is_builtin_impl(PyModuleDef module, PyObject name) -/[clinic end generated code: checksum=353938c1d55210a1e3850d3ccba7539d02165cac]/ +/[clinic end generated code: checksum=51c6139dcfd9bee1f40980ea68b7797f8489d69a]/ { return PyLong_FromLong(is_builtin(name)); } @@ -2112,7 +2112,7 @@ Returns True if the module name correspo [clinic start generated code]/ PyDoc_STRVAR(imp_is_frozen__doc_, -"is_frozen(name)\n" +"is_frozen(module, name)\n" "Returns True if the module name corresponds to a frozen module."); #define _IMP_IS_FROZEN_METHODDEF [](#l30.191) @@ -2139,7 +2139,7 @@ exit: static PyObject _imp_is_frozen_impl(PyModuleDef module, PyObject name) -/[clinic end generated code: checksum=978b547ddcb76fa6c4a181ad53569c9acf382c7b]/ +/[clinic end generated code: checksum=4b079fb45a495835056ea5604735d552d222be5c]/ { const struct frozen p; @@ -2161,7 +2161,7 @@ Loads an extension module. [clinic start generated code]/ PyDoc_STRVAR(imp_load_dynamic__doc, -"load_dynamic(name, path, file=None)\n" +"load_dynamic(module, name, path, file=None)\n" "Loads an extension module."); #define _IMP_LOAD_DYNAMIC_METHODDEF [](#l30.209) @@ -2190,7 +2190,7 @@ exit: static PyObject * _imp_load_dynamic_impl(PyModuleDef module, PyObject name, PyObject path, PyObject file) -/[clinic end generated code: checksum=6795f65d9ce003ccaf08e4e8eef484dc52e262d0]/ +/[clinic end generated code: checksum=63e051fd0d0350c785bf185be41b0892f9920622]/ { PyObject *mod; FILE *fp;

--- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -139,9 +139,9 @@ def is_legal_py_identifier(s):

so if they're used Argument Clinic will add "_value" to the end

of the name in C.

c_keywords = set(""" -asm auto break case char cls const continue default do double -else enum extern float for goto if inline int long module null -register return self short signed sizeof static struct switch +asm auto break case char const continue default do double +else enum extern float for goto if inline int long +register return short signed sizeof static struct switch typedef typeof union unsigned void volatile while """.strip().split()) @@ -635,6 +635,9 @@ methoddef_define def output_templates(self, f): parameters = list(f.parameters.values())

has_option_groups = parameters and (parameters[0].group or parameters[-1].group) @@ -679,8 +682,11 @@ methoddef_define return_value_declaration = "PyObject *return_value = NULL;" methoddef_define = templates['methoddef_define']

@@ -858,6 +864,8 @@ methoddef_define add, output = text_accumulator() parameters = list(f.parameters.values())

groups = [] group = None @@ -936,14 +944,69 @@ methoddef_define data = CRenderData() parameters = list(f.parameters.values())

+ converters = [p.converter for p in parameters]

+

+

+

+

+

+

+

+

+ template_dict = {} full_name = f.full_name template_dict['full_name'] = full_name

+ template_dict['name'] = name if f.c_basename: @@ -953,6 +1016,7 @@ methoddef_define if fields[-1] == 'new': fields.pop() c_basename = "_".join(fields) + template_dict['c_basename'] = c_basename methoddef_name = "{}_METHODDEF".format(c_basename.upper()) @@ -960,67 +1024,7 @@ methoddef_define template_dict['docstring'] = self.docstring_for_c_string(f)

-

-

-

-

-

-

-

-

-

f.return_converter.render(f, data) template_dict['impl_return_type'] = f.return_converter.type @@ -1036,15 +1040,16 @@ methoddef_define template_dict['cleanup'] = "".join(data.cleanup) template_dict['return_value'] = data.return_value

if has_option_groups: self.render_option_group_parsing(f, template_dict)

- for name, destination in clinic.field_destinations.items(): template = templates[name] if has_option_groups: @@ -1077,6 +1082,7 @@ methoddef_define + @contextlib.contextmanager def OverrideStdioWith(stdout): saved_stdout = sys.stdout @@ -1775,7 +1781,9 @@ unsupported_special_methods = set(""" """.strip().split()) -INVALID, CALLABLE, STATIC_METHOD, CLASS_METHOD, METHOD_INIT, METHOD_NEW = range(6) +INVALID, CALLABLE, STATIC_METHOD, CLASS_METHOD, METHOD_INIT, METHOD_NEW = """ +INVALID, CALLABLE, STATIC_METHOD, CLASS_METHOD, METHOD_INIT, METHOD_NEW +""".replace(",", "").strip().split() class Function: """ @@ -1969,6 +1977,19 @@ class CConverter(metaclass=CConverterAut # Only used by format units ending with '#'. length = False

+

+

@@ -1998,11 +2019,23 @@ class CConverter(metaclass=CConverterAut def is_optional(self): return (self.default is not unspecified)

+

+

+

@@ -2016,12 +2049,6 @@ class CConverter(metaclass=CConverterAut if initializers: data.initializers.append('/* initializers for ' + name + ' */\n' + initializers.rstrip())

- # keywords data.keywords.append(original_name) @@ -2035,16 +2062,19 @@ class CConverter(metaclass=CConverterAut # parse_arguments self.parse_argument(data.parse_arguments)

- # cleanup cleanup = self.cleanup() if cleanup: data.cleanup.append('/* Cleanup for ' + name + ' */\n' + cleanup.rstrip() + "\n")

+ def length_name(self): """Computes the name of the associated "length" variable.""" if not self.length: @@ -2318,7 +2348,7 @@ class str_converter(CConverter): format_unit = 'et#' if format_unit.endswith('#'):

@@ -2421,35 +2451,108 @@ class Py_buffer_converter(CConverter): return "".join(["if (", name, ".obj)\n PyBuffer_Release(&", name, ");\n"]) +def correct_name_for_self(f):

+ + class self_converter(CConverter): """ A special-case converter: this is the default converter used for "self". """

+ + def converter_init(self, *, type=None): f = self.function

-

+

+

+

+

def render(self, parameter, data):

+

+

+

@@ -2997,7 +3100,7 @@ class DSLParser: if not return_converter: return_converter = init_return_converter() elif fields[-1] in unsupported_special_methods:

if not return_converter: return_converter = CReturnConverter() @@ -3007,6 +3110,13 @@ class DSLParser: self.function = Function(name=function_name, full_name=full_name, module=module, cls=cls, c_basename=c_basename, return_converter=return_converter, kind=self.kind, coexist=self.coexist) self.block.signatures.append(self.function) +

+ (cls or module).functions.append(self.function) self.next(self.state_parameters_start) @@ -3173,34 +3283,43 @@ class DSLParser: try: module = ast.parse(ast_input)

-

-

-

-

-

-

+

+

+

+

+

+

expr = module.body[0].value @@ -3263,18 +3382,22 @@ class DSLParser: fail('{} is not a valid {}converter'.format(name, legacy_str)) converter = dict[name](parameter_name, self.function, value, **kwargs)

+ if isinstance(converter, self_converter):

-

+ p = Parameter(parameter_name, kind, function=self.function, converter=converter, default=value, group=self.group) if parameter_name in self.function.parameters: @@ -3333,7 +3456,7 @@ class DSLParser: self.parameter_state = self.ps_seen_slash # fixup preceeding parameters for p in self.function.parameters.values():

@@ -3394,6 +3517,11 @@ class DSLParser: def format_docstring(self): f = self.function

+ add, output = text_accumulator() parameters = list(f.parameters.values()) @@ -3401,7 +3529,7 @@ class DSLParser: ## docstring first line ##

@@ -3409,17 +3537,24 @@ class DSLParser: add('(') # populate "right_bracket_count" field for every parameter

+

right_bracket_count = 0 @@ -3439,6 +3574,9 @@ class DSLParser: add_comma = False for p in parameters:

+ assert p.name if p.is_keyword_only() and not added_star: @@ -3446,8 +3584,10 @@ class DSLParser: if add_comma: add(', ') add('*') -

+

@@ -3560,9 +3700,6 @@ class DSLParser: if not self.function: return

- if self.keyword_only: values = self.function.parameters.values() if not values: @@ -3582,6 +3719,8 @@ class DSLParser: self.function.docstring = self.format_docstring() + +

maps strings to callables.

the callable should return an object

that implements the clinic parser

@@ -3607,6 +3746,7 @@ def main(argv): cmdline = argparse.ArgumentParser() cmdline.add_argument("-f", "--force", action='store_true') cmdline.add_argument("-o", "--output", type=str)

@@ -3701,6 +3843,8 @@ def main(argv): sys.exit(-1) for filename in ns.filename: