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

Skip to content

Commit 7737757

Browse files
committed
Issue #16443: Add docstrings to regular expression match objects.
Patch by Anton Kasyanov.
2 parents 75d5a18 + 70dcef4 commit 7737757

3 files changed

Lines changed: 62 additions & 15 deletions

File tree

Misc/ACKS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,10 @@ Jan Kaliszewski
601601
Peter van Kampen
602602
Rafe Kaplan
603603
Jacob Kaplan-Moss
604+
Jan Kaliszewski
604605
Janne Karila
605606
Per Øyvind Karlsen
607+
Anton Kasyanov
606608
Lou Kates
607609
Hiroaki Kawai
608610
Sebastien Keim

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ Core and Builtins
176176
Library
177177
-------
178178

179+
- Issue #16443: Add docstrings to regular expression match objects.
180+
Patch by Anton Kasyanov.
181+
182+
- Issue #15701: Fix HTTPError info method call to return the headers information.
183+
179184
- Issue #16752: Add a missing import to modulefinder. Patch by Berker Peksag.
180185

181186
- Issue #16646: ftplib.FTP.makeport() might lose socket error details.

Modules/_sre.c

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2527,35 +2527,35 @@ pattern_deepcopy(PatternObject* self, PyObject* memo)
25272527
}
25282528

25292529
PyDoc_STRVAR(pattern_match_doc,
2530-
"match(string[, pos[, endpos]]) --> match object or None.\n\
2530+
"match(string[, pos[, endpos]]) -> match object or None.\n\
25312531
Matches zero or more characters at the beginning of the string");
25322532

25332533
PyDoc_STRVAR(pattern_search_doc,
2534-
"search(string[, pos[, endpos]]) --> match object or None.\n\
2534+
"search(string[, pos[, endpos]]) -> match object or None.\n\
25352535
Scan through string looking for a match, and return a corresponding\n\
25362536
MatchObject instance. Return None if no position in the string matches.");
25372537

25382538
PyDoc_STRVAR(pattern_split_doc,
2539-
"split(string[, maxsplit = 0]) --> list.\n\
2539+
"split(string[, maxsplit = 0]) -> list.\n\
25402540
Split string by the occurrences of pattern.");
25412541

25422542
PyDoc_STRVAR(pattern_findall_doc,
2543-
"findall(string[, pos[, endpos]]) --> list.\n\
2543+
"findall(string[, pos[, endpos]]) -> list.\n\
25442544
Return a list of all non-overlapping matches of pattern in string.");
25452545

25462546
PyDoc_STRVAR(pattern_finditer_doc,
2547-
"finditer(string[, pos[, endpos]]) --> iterator.\n\
2547+
"finditer(string[, pos[, endpos]]) -> iterator.\n\
25482548
Return an iterator over all non-overlapping matches for the \n\
25492549
RE pattern in string. For each match, the iterator returns a\n\
25502550
match object.");
25512551

25522552
PyDoc_STRVAR(pattern_sub_doc,
2553-
"sub(repl, string[, count = 0]) --> newstring\n\
2553+
"sub(repl, string[, count = 0]) -> newstring.\n\
25542554
Return the string obtained by replacing the leftmost non-overlapping\n\
25552555
occurrences of pattern in string by the replacement repl.");
25562556

25572557
PyDoc_STRVAR(pattern_subn_doc,
2558-
"subn(repl, string[, count = 0]) --> (newstring, number of subs)\n\
2558+
"subn(repl, string[, count = 0]) -> (newstring, number of subs)\n\
25592559
Return the tuple (new_string, number_of_subs_made) found by replacing\n\
25602560
the leftmost non-overlapping occurrences of pattern with the\n\
25612561
replacement repl.");
@@ -3543,14 +3543,54 @@ match_deepcopy(MatchObject* self, PyObject* memo)
35433543
#endif
35443544
}
35453545

3546+
PyDoc_STRVAR(match_doc,
3547+
"The result of re.match() and re.search().\n\
3548+
Match objects always have a boolean value of True.");
3549+
3550+
PyDoc_STRVAR(match_group_doc,
3551+
"group([group1, ...]) -> str or tuple.\n\
3552+
Return subgroup(s) of the match by indices or names.\n\
3553+
For 0 returns the entire match.");
3554+
3555+
PyDoc_STRVAR(match_start_doc,
3556+
"start([group=0]) -> int.\n\
3557+
Return index of the start of the substring matched by group.");
3558+
3559+
PyDoc_STRVAR(match_end_doc,
3560+
"end([group=0]) -> int.\n\
3561+
Return index of the end of the substring matched by group.");
3562+
3563+
PyDoc_STRVAR(match_span_doc,
3564+
"span([group]) -> tuple.\n\
3565+
For MatchObject m, return the 2-tuple (m.start(group), m.end(group)).");
3566+
3567+
PyDoc_STRVAR(match_groups_doc,
3568+
"groups([default=None]) -> tuple.\n\
3569+
Return a tuple containing all the subgroups of the match, from 1.\n\
3570+
The default argument is used for groups\n\
3571+
that did not participate in the match");
3572+
3573+
PyDoc_STRVAR(match_groupdict_doc,
3574+
"groupdict([default=None]) -> dict.\n\
3575+
Return a dictionary containing all the named subgroups of the match,\n\
3576+
keyed by the subgroup name. The default argument is used for groups\n\
3577+
that did not participate in the match");
3578+
3579+
PyDoc_STRVAR(match_expand_doc,
3580+
"expand(template) -> str.\n\
3581+
Return the string obtained by doing backslash substitution\n\
3582+
on the string template, as done by the sub() method.");
3583+
35463584
static PyMethodDef match_methods[] = {
3547-
{"group", (PyCFunction) match_group, METH_VARARGS},
3548-
{"start", (PyCFunction) match_start, METH_VARARGS},
3549-
{"end", (PyCFunction) match_end, METH_VARARGS},
3550-
{"span", (PyCFunction) match_span, METH_VARARGS},
3551-
{"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS},
3552-
{"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS},
3553-
{"expand", (PyCFunction) match_expand, METH_O},
3585+
{"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc},
3586+
{"start", (PyCFunction) match_start, METH_VARARGS, match_start_doc},
3587+
{"end", (PyCFunction) match_end, METH_VARARGS, match_end_doc},
3588+
{"span", (PyCFunction) match_span, METH_VARARGS, match_span_doc},
3589+
{"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS,
3590+
match_groups_doc},
3591+
{"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS,
3592+
match_groupdict_doc},
3593+
{"expand", (PyCFunction) match_expand, METH_O, match_expand_doc},
35543594
{"__copy__", (PyCFunction) match_copy, METH_NOARGS},
35553595
{"__deepcopy__", (PyCFunction) match_deepcopy, METH_O},
35563596
{NULL, NULL}
@@ -3629,7 +3669,7 @@ static PyTypeObject Match_Type = {
36293669
0, /* tp_setattro */
36303670
0, /* tp_as_buffer */
36313671
Py_TPFLAGS_DEFAULT, /* tp_flags */
3632-
0, /* tp_doc */
3672+
match_doc, /* tp_doc */
36333673
0, /* tp_traverse */
36343674
0, /* tp_clear */
36353675
0, /* tp_richcompare */

0 commit comments

Comments
 (0)