diff options
author | Larry Hastings <larry@hastings.org> | 2014-01-07 19:53:01 (GMT) |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2014-01-07 19:53:01 (GMT) |
commit | 16c5191ab3443aa5c1f835848514f94c696a8c4d (patch) | |
tree | a064b4a173dddc48b34bc48b95601809c3bf9ba7 /Modules | |
parent | 0bce6e746274980fb934ee8f2a06cbf8f8a54e3e (diff) | |
download | cpython-16c5191ab3443aa5c1f835848514f94c696a8c4d.zip cpython-16c5191ab3443aa5c1f835848514f94c696a8c4d.tar.gz cpython-16c5191ab3443aa5c1f835848514f94c696a8c4d.tar.bz2 |
Issue #20144: Argument Clinic now supports simple constants as parameter
default values. inspect.Signature correspondingly supports them in
__text_signature__ fields for builtins.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sre.c | 68 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 12 |
2 files changed, 62 insertions, 18 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c index 55a86c2..6be2e59 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -526,21 +526,58 @@ sre_search(SRE_STATE* state, SRE_CODE* pattern) return sre_ucs4_search(state, pattern); } -static PyObject* -pattern_match(PatternObject* self, PyObject* args, PyObject* kw) +/*[clinic] +module _sre +class _sre.SRE_Pattern + +_sre.SRE_Pattern.match as pattern_match + + self: self(type="PatternObject *") + pattern: object + pos: Py_ssize_t = 0 + endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize + +Matches zero or more characters at the beginning of the string. +[clinic]*/ + +PyDoc_STRVAR(pattern_match__doc__, +"match(pattern, pos=0, endpos=sys.maxsize)\n" +"Matches zero or more characters at the beginning of the string."); + +#define PATTERN_MATCH_METHODDEF \ + {"match", (PyCFunction)pattern_match, METH_VARARGS|METH_KEYWORDS, pattern_match__doc__}, + +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) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"pattern", "pos", "endpos", NULL}; + PyObject *pattern; + Py_ssize_t pos = 0; + Py_ssize_t endpos = PY_SSIZE_T_MAX; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O|nn:match", _keywords, + &pattern, &pos, &endpos)) + goto exit; + return_value = pattern_match_impl((PatternObject *)self, pattern, pos, endpos); + +exit: + return return_value; +} + +static PyObject * +pattern_match_impl(PatternObject *self, PyObject *pattern, Py_ssize_t pos, Py_ssize_t endpos) +/*[clinic checksum: 63e59c5f3019efe6c1f3acdec42b2d3595e14a09]*/ { SRE_STATE state; Py_ssize_t status; + PyObject *string; - PyObject* string; - Py_ssize_t start = 0; - Py_ssize_t end = PY_SSIZE_T_MAX; - static char* kwlist[] = { "pattern", "pos", "endpos", NULL }; - if (!PyArg_ParseTupleAndKeywords(args, kw, "O|nn:match", kwlist, - &string, &start, &end)) - return NULL; - - string = state_init(&state, self, string, start, end); + string = state_init(&state, (PatternObject *)self, pattern, pos, endpos); if (!string) return NULL; @@ -556,7 +593,7 @@ pattern_match(PatternObject* self, PyObject* args, PyObject* kw) state_fini(&state); - return pattern_new_match(self, &state, status); + return (PyObject *)pattern_new_match(self, &state, status); } static PyObject* @@ -1254,10 +1291,6 @@ done: return result; } -PyDoc_STRVAR(pattern_match_doc, -"match(string[, pos[, endpos]]) -> match object or None.\n\ - Matches zero or more characters at the beginning of the string"); - PyDoc_STRVAR(pattern_fullmatch_doc, "fullmatch(string[, pos[, endpos]]) -> match object or None.\n\ Matches against all of the string"); @@ -1295,8 +1328,7 @@ PyDoc_STRVAR(pattern_subn_doc, PyDoc_STRVAR(pattern_doc, "Compiled regular expression objects"); static PyMethodDef pattern_methods[] = { - {"match", (PyCFunction) pattern_match, METH_VARARGS|METH_KEYWORDS, - pattern_match_doc}, + PATTERN_MATCH_METHODDEF {"fullmatch", (PyCFunction) pattern_fullmatch, METH_VARARGS|METH_KEYWORDS, pattern_fullmatch_doc}, {"search", (PyCFunction) pattern_search, METH_VARARGS|METH_KEYWORDS, diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index a0cffde..b8fe8d5 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2869,6 +2869,15 @@ PyDoc_STRVAR(docstring_with_signature_and_extra_newlines, "This docstring has a valid signature and some extra newlines." ); +PyDoc_STRVAR(docstring_with_signature_with_defaults, +"docstring_with_signature_with_defaults(s='avocado', d=3.14, i=35, c=sys.maxsize, n=None, t=True, f=False)\n" +"\n" +"\n" +"\n" +"This docstring has a valid signature with parameters,\n" +"and the parameters take defaults of varying types." +); + #ifdef WITH_THREAD typedef struct { PyThread_type_lock start_event; @@ -3087,6 +3096,9 @@ static PyMethodDef TestMethods[] = { {"docstring_with_signature_and_extra_newlines", (PyCFunction)test_with_docstring, METH_NOARGS, docstring_with_signature_and_extra_newlines}, + {"docstring_with_signature_with_defaults", + (PyCFunction)test_with_docstring, METH_NOARGS, + docstring_with_signature_with_defaults}, #ifdef WITH_THREAD {"call_in_temporary_c_thread", call_in_temporary_c_thread, METH_O, PyDoc_STR("set_error_class(error_class) -> None")}, |