mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
for C files to generate argument parsing code. (See PEP 436.)
This commit is contained in:
parent
5ceae41083
commit
3182680210
12 changed files with 4016 additions and 276 deletions
|
@ -2160,9 +2160,31 @@ dict_richcompare(PyObject *v, PyObject *w, int op)
|
|||
return res;
|
||||
}
|
||||
|
||||
/*[clinic]
|
||||
module dict
|
||||
|
||||
@coexist
|
||||
dict.__contains__
|
||||
|
||||
key: object
|
||||
/
|
||||
|
||||
True if D has a key k, else False"
|
||||
[clinic]*/
|
||||
|
||||
PyDoc_STRVAR(dict___contains____doc__,
|
||||
"True if D has a key k, else False\"\n"
|
||||
"\n"
|
||||
"dict.__contains__(key)");
|
||||
|
||||
#define DICT___CONTAINS___METHODDEF \
|
||||
{"__contains__", (PyCFunction)dict___contains__, METH_O|METH_COEXIST, dict___contains____doc__},
|
||||
|
||||
static PyObject *
|
||||
dict_contains(PyDictObject *mp, PyObject *key)
|
||||
dict___contains__(PyObject *self, PyObject *key)
|
||||
/*[clinic checksum: 61c5c802ea1d35699a1a754f1f3538ea9b259cf4]*/
|
||||
{
|
||||
register PyDictObject *mp = (PyDictObject *)self;
|
||||
Py_hash_t hash;
|
||||
PyDictKeyEntry *ep;
|
||||
PyObject **value_addr;
|
||||
|
@ -2447,9 +2469,6 @@ _PyDict_KeysSize(PyDictKeysObject *keys)
|
|||
return sizeof(PyDictKeysObject) + (DK_SIZE(keys)-1) * sizeof(PyDictKeyEntry);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(contains__doc__,
|
||||
"D.__contains__(k) -> True if D has a key k, else False");
|
||||
|
||||
PyDoc_STRVAR(getitem__doc__, "x.__getitem__(y) <==> x[y]");
|
||||
|
||||
PyDoc_STRVAR(sizeof__doc__,
|
||||
|
@ -2498,8 +2517,7 @@ PyDoc_STRVAR(values__doc__,
|
|||
"D.values() -> an object providing a view on D's values");
|
||||
|
||||
static PyMethodDef mapp_methods[] = {
|
||||
{"__contains__",(PyCFunction)dict_contains, METH_O | METH_COEXIST,
|
||||
contains__doc__},
|
||||
DICT___CONTAINS___METHODDEF
|
||||
{"__getitem__", (PyCFunction)dict_subscript, METH_O | METH_COEXIST,
|
||||
getitem__doc__},
|
||||
{"__sizeof__", (PyCFunction)dict_sizeof, METH_NOARGS,
|
||||
|
|
|
@ -12656,28 +12656,76 @@ unicode_swapcase(PyObject *self)
|
|||
return case_operation(self, do_swapcase);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(maketrans__doc__,
|
||||
"str.maketrans(x[, y[, z]]) -> dict (static method)\n\
|
||||
\n\
|
||||
Return a translation table usable for str.translate().\n\
|
||||
If there is only one argument, it must be a dictionary mapping Unicode\n\
|
||||
ordinals (integers) or characters to Unicode ordinals, strings or None.\n\
|
||||
Character keys will be then converted to ordinals.\n\
|
||||
If there are two arguments, they must be strings of equal length, and\n\
|
||||
in the resulting dictionary, each character in x will be mapped to the\n\
|
||||
character at the same position in y. If there is a third argument, it\n\
|
||||
must be a string, whose characters will be mapped to None in the result.");
|
||||
/*[clinic]
|
||||
module str
|
||||
|
||||
static PyObject*
|
||||
@staticmethod
|
||||
str.maketrans as unicode_maketrans
|
||||
|
||||
x: object
|
||||
|
||||
y: unicode=NULL
|
||||
|
||||
z: unicode=NULL
|
||||
|
||||
/
|
||||
|
||||
Return a translation table usable for str.translate().
|
||||
|
||||
If there is only one argument, it must be a dictionary mapping Unicode
|
||||
ordinals (integers) or characters to Unicode ordinals, strings or None.
|
||||
Character keys will be then converted to ordinals.
|
||||
If there are two arguments, they must be strings of equal length, and
|
||||
in the resulting dictionary, each character in x will be mapped to the
|
||||
character at the same position in y. If there is a third argument, it
|
||||
must be a string, whose characters will be mapped to None in the result.
|
||||
[clinic]*/
|
||||
|
||||
PyDoc_STRVAR(unicode_maketrans__doc__,
|
||||
"Return a translation table usable for str.translate().\n"
|
||||
"\n"
|
||||
"str.maketrans(x, y=None, z=None)\n"
|
||||
"\n"
|
||||
"If there is only one argument, it must be a dictionary mapping Unicode\n"
|
||||
"ordinals (integers) or characters to Unicode ordinals, strings or None.\n"
|
||||
"Character keys will be then converted to ordinals.\n"
|
||||
"If there are two arguments, they must be strings of equal length, and\n"
|
||||
"in the resulting dictionary, each character in x will be mapped to the\n"
|
||||
"character at the same position in y. If there is a third argument, it\n"
|
||||
"must be a string, whose characters will be mapped to None in the result.");
|
||||
|
||||
#define UNICODE_MAKETRANS_METHODDEF \
|
||||
{"maketrans", (PyCFunction)unicode_maketrans, METH_VARARGS|METH_STATIC, unicode_maketrans__doc__},
|
||||
|
||||
static PyObject *
|
||||
unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z);
|
||||
|
||||
static PyObject *
|
||||
unicode_maketrans(PyObject *null, PyObject *args)
|
||||
{
|
||||
PyObject *x, *y = NULL, *z = NULL;
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *x;
|
||||
PyObject *y = NULL;
|
||||
PyObject *z = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args,
|
||||
"O|UU:maketrans",
|
||||
&x, &y, &z))
|
||||
goto exit;
|
||||
return_value = unicode_maketrans_impl(x, y, z);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
unicode_maketrans_impl(PyObject *x, PyObject *y, PyObject *z)
|
||||
/*[clinic checksum: 137db9c3199e7906b7967009f511c24fa3235b5f]*/
|
||||
{
|
||||
PyObject *new = NULL, *key, *value;
|
||||
Py_ssize_t i = 0;
|
||||
int res;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O|UU:maketrans", &x, &y, &z))
|
||||
return NULL;
|
||||
new = PyDict_New();
|
||||
if (!new)
|
||||
return NULL;
|
||||
|
@ -13317,8 +13365,7 @@ static PyMethodDef unicode_methods[] = {
|
|||
{"format", (PyCFunction) do_string_format, METH_VARARGS | METH_KEYWORDS, format__doc__},
|
||||
{"format_map", (PyCFunction) do_string_format_map, METH_O, format_map__doc__},
|
||||
{"__format__", (PyCFunction) unicode__format__, METH_VARARGS, p_format__doc__},
|
||||
{"maketrans", (PyCFunction) unicode_maketrans,
|
||||
METH_VARARGS | METH_STATIC, maketrans__doc__},
|
||||
UNICODE_MAKETRANS_METHODDEF
|
||||
{"__sizeof__", (PyCFunction) unicode__sizeof__, METH_NOARGS, sizeof__doc__},
|
||||
#if 0
|
||||
/* These methods are just used for debugging the implementation. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue