Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9447874

Browse files
committed
Add docstrings for regular expression objects and methods.
1 parent 596ba4d commit 9447874

1 file changed

Lines changed: 51 additions & 8 deletions

File tree

Modules/_sre.c

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,15 +2672,58 @@ pattern_deepcopy(PatternObject* self, PyObject* args)
26722672
#endif
26732673
}
26742674

2675+
PyDoc_STRVAR(pattern_match_doc,
2676+
"match(string[, pos[, endpos]]) --> match object or None.\n\
2677+
Matches zero or more characters at the beginning of the string");
2678+
2679+
PyDoc_STRVAR(pattern_search_doc,
2680+
"search(string[, pos[, endpos]]) --> match object or None.\n\
2681+
Scan through string looking for a match, and return a corresponding\n\
2682+
MatchObject instance. Return None if no position in the string matches.");
2683+
2684+
PyDoc_STRVAR(pattern_split_doc,
2685+
"split(string[, maxsplit = 0]) --> list.\n\
2686+
Split string by the occurrences of pattern.");
2687+
2688+
PyDoc_STRVAR(pattern_findall_doc,
2689+
"findall(string[, pos[, endpos]]) --> list.\n\
2690+
Return a list of all non-overlapping matches of pattern in string.");
2691+
2692+
PyDoc_STRVAR(pattern_finditer_doc,
2693+
"finditer(string[, pos[, endpos]]) --> iterator.\n\
2694+
Return an iterator over all non-overlapping matches for the \n\
2695+
RE pattern in string. For each match, the iterator returns a\n\
2696+
match object.");
2697+
2698+
PyDoc_STRVAR(pattern_sub_doc,
2699+
"sub(repl, string[, count = 0]) --> newstring\n\
2700+
Return the string obtained by replacing the leftmost non-overlapping\n\
2701+
occurrences of pattern in string by the replacement repl.");
2702+
2703+
PyDoc_STRVAR(pattern_subn_doc,
2704+
"subn(repl, string[, count = 0]) --> (newstring, number of subs)\n\
2705+
Return the tuple (new_string, number_of_subs_made) found by replacing\n\
2706+
the leftmost non-overlapping occurrences of pattern with the\n\
2707+
replacement repl.");
2708+
2709+
PyDoc_STRVAR(pattern_doc, "Compiled regular expression objects");
2710+
26752711
static PyMethodDef pattern_methods[] = {
2676-
{"match", (PyCFunction) pattern_match, METH_VARARGS|METH_KEYWORDS},
2677-
{"search", (PyCFunction) pattern_search, METH_VARARGS|METH_KEYWORDS},
2678-
{"sub", (PyCFunction) pattern_sub, METH_VARARGS|METH_KEYWORDS},
2679-
{"subn", (PyCFunction) pattern_subn, METH_VARARGS|METH_KEYWORDS},
2680-
{"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS},
2681-
{"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS},
2712+
{"match", (PyCFunction) pattern_match, METH_VARARGS|METH_KEYWORDS,
2713+
pattern_match_doc},
2714+
{"search", (PyCFunction) pattern_search, METH_VARARGS|METH_KEYWORDS,
2715+
pattern_search_doc},
2716+
{"sub", (PyCFunction) pattern_sub, METH_VARARGS|METH_KEYWORDS,
2717+
pattern_sub_doc},
2718+
{"subn", (PyCFunction) pattern_subn, METH_VARARGS|METH_KEYWORDS,
2719+
pattern_subn_doc},
2720+
{"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS,
2721+
pattern_split_doc},
2722+
{"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS,
2723+
pattern_findall_doc},
26822724
#if PY_VERSION_HEX >= 0x02020000
2683-
{"finditer", (PyCFunction) pattern_finditer, METH_VARARGS},
2725+
{"finditer", (PyCFunction) pattern_finditer, METH_VARARGS,
2726+
pattern_finditer_doc},
26842727
#endif
26852728
{"scanner", (PyCFunction) pattern_scanner, METH_VARARGS},
26862729
{"__copy__", (PyCFunction) pattern_copy, METH_VARARGS},
@@ -2741,7 +2784,7 @@ statichere PyTypeObject Pattern_Type = {
27412784
0, /* tp_setattro */
27422785
0, /* tp_as_buffer */
27432786
Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
2744-
0, /* tp_doc */
2787+
pattern_doc, /* tp_doc */
27452788
0, /* tp_traverse */
27462789
0, /* tp_clear */
27472790
0, /* tp_richcompare */

0 commit comments

Comments
 (0)