]> granicus.if.org Git - python/commitdiff
Issue #16443: Add docstrings to regular expression match objects.
authorAndrew Svetlov <andrew.svetlov@gmail.com>
Sun, 23 Dec 2012 17:59:27 +0000 (19:59 +0200)
committerAndrew Svetlov <andrew.svetlov@gmail.com>
Sun, 23 Dec 2012 17:59:27 +0000 (19:59 +0200)
Patch by Anton Kasyanov.

1  2 
Misc/ACKS
Misc/NEWS
Modules/_sre.c

diff --cc Misc/ACKS
index e4d178355af73b9f640f44371a8f0d217afc7242,f9c75ab36fb88a446c6ba5c7828ddae09b21978a..af9aa062503458cf61aa3784648ef749fbef67cc
+++ b/Misc/ACKS
@@@ -598,8 -542,8 +598,10 @@@ Jan Kaliszewsk
  Peter van Kampen
  Rafe Kaplan
  Jacob Kaplan-Moss
+ Jan Kaliszewski
 +Janne Karila
 +Per Ã˜yvind Karlsen
+ Anton Kasyanov
  Lou Kates
  Hiroaki Kawai
  Sebastien Keim
diff --cc Misc/NEWS
index 31b33561818897db9ce2bd641bff6a13b3829334,e7fa7d9dff5b42b9cc3175870eb67e2850957cf2..89e2f2cc39434ee8b613eabd55965b4cdd36080e
+++ b/Misc/NEWS
@@@ -114,10 -179,11 +114,13 @@@ Core and Builtin
  Library
  -------
  
+ - Issue #16443: Add docstrings to regular expression match objects.
+   Patch by Anton Kasyanov.
  - Issue #15701: Fix HTTPError info method call to return the headers information.
  
 +- Issue #16752: Add a missing import to modulefinder. Patch by Berker Peksag.
 +
  - Issue #16646: ftplib.FTP.makeport() might lose socket error details.
    (patch by Serhiy Storchaka)
  
diff --cc Modules/_sre.c
index 20a7d97b858442d85dfd44ee64017c2ced52bce1,99101e7993e11cfaf5ef56e1ba1efc611f935fc8..ee353bb1617c6adea20a554c73cd62b5d6ab5a06
@@@ -2527,35 -2559,35 +2527,35 @@@ pattern_deepcopy(PatternObject* self, P
  }
  
  PyDoc_STRVAR(pattern_match_doc,
- "match(string[, pos[, endpos]]) --> match object or None.\n\
 -"match(string[, pos[, endpos]]) -> match object or None.\n\n\
++"match(string[, pos[, endpos]]) -> match object or None.\n\
      Matches zero or more characters at the beginning of the string");
  
  PyDoc_STRVAR(pattern_search_doc,
- "search(string[, pos[, endpos]]) --> match object or None.\n\
 -"search(string[, pos[, endpos]]) -> match object or None.\n\n\
++"search(string[, pos[, endpos]]) -> match object or None.\n\
      Scan through string looking for a match, and return a corresponding\n\
      MatchObject instance. Return None if no position in the string matches.");
  
  PyDoc_STRVAR(pattern_split_doc,
- "split(string[, maxsplit = 0])  --> list.\n\
 -"split(string[, maxsplit = 0])  -> list.\n\n\
++"split(string[, maxsplit = 0])  -> list.\n\
      Split string by the occurrences of pattern.");
  
  PyDoc_STRVAR(pattern_findall_doc,
- "findall(string[, pos[, endpos]]) --> list.\n\
 -"findall(string[, pos[, endpos]]) -> list.\n\n\
++"findall(string[, pos[, endpos]]) -> list.\n\
     Return a list of all non-overlapping matches of pattern in string.");
  
  PyDoc_STRVAR(pattern_finditer_doc,
- "finditer(string[, pos[, endpos]]) --> iterator.\n\
 -"finditer(string[, pos[, endpos]]) -> iterator.\n\n\
++"finditer(string[, pos[, endpos]]) -> iterator.\n\
      Return an iterator over all non-overlapping matches for the \n\
      RE pattern in string. For each match, the iterator returns a\n\
      match object.");
  
  PyDoc_STRVAR(pattern_sub_doc,
- "sub(repl, string[, count = 0]) --> newstring\n\
 -"sub(repl, string[, count = 0]) -> newstring.\n\n\
++"sub(repl, string[, count = 0]) -> newstring.\n\
      Return the string obtained by replacing the leftmost non-overlapping\n\
      occurrences of pattern in string by the replacement repl.");
  
  PyDoc_STRVAR(pattern_subn_doc,
- "subn(repl, string[, count = 0]) --> (newstring, number of subs)\n\
 -"subn(repl, string[, count = 0]) -> (newstring, number of subs)\n\n\
++"subn(repl, string[, count = 0]) -> (newstring, number of subs)\n\
      Return the tuple (new_string, number_of_subs_made) found by replacing\n\
      the leftmost non-overlapping occurrences of pattern with the\n\
      replacement repl.");
@@@ -3543,14 -3579,54 +3543,54 @@@ match_deepcopy(MatchObject* self, PyObj
  #endif
  }
  
 -"group([group1, ...]) -> str or tuple.\n\n\
+ PyDoc_STRVAR(match_doc,
+ "The result of re.match() and re.search().\n\
+ Match objects always have a boolean value of True.");
+ PyDoc_STRVAR(match_group_doc,
 -"start([group=0]) -> int.\n\n\
++"group([group1, ...]) -> str or tuple.\n\
+     Return subgroup(s) of the match by indices or names.\n\
+     For 0 returns the entire match.");
+ PyDoc_STRVAR(match_start_doc,
 -"end([group=0]) -> int.\n\n\
++"start([group=0]) -> int.\n\
+     Return index of the start of the substring matched by group.");
+ PyDoc_STRVAR(match_end_doc,
 -"span([group]) -> tuple.\n\n\
++"end([group=0]) -> int.\n\
+     Return index of the end of the substring matched by group.");
+ PyDoc_STRVAR(match_span_doc,
 -"groups([default=None]) -> tuple.\n\n\
++"span([group]) -> tuple.\n\
+     For MatchObject m, return the 2-tuple (m.start(group), m.end(group)).");
+ PyDoc_STRVAR(match_groups_doc,
 -"groupdict([default=None]) -> dict.\n\n\
++"groups([default=None]) -> tuple.\n\
+     Return a tuple containing all the subgroups of the match, from 1.\n\
+     The default argument is used for groups\n\
+     that did not participate in the match");
+ PyDoc_STRVAR(match_groupdict_doc,
 -"expand(template) -> str.\n\n\
++"groupdict([default=None]) -> dict.\n\
+     Return a dictionary containing all the named subgroups of the match,\n\
+     keyed by the subgroup name. The default argument is used for groups\n\
+     that did not participate in the match");
+ PyDoc_STRVAR(match_expand_doc,
++"expand(template) -> str.\n\
+     Return the string obtained by doing backslash substitution\n\
+     on the string template, as done by the sub() method.");
  static PyMethodDef match_methods[] = {
-     {"group", (PyCFunction) match_group, METH_VARARGS},
-     {"start", (PyCFunction) match_start, METH_VARARGS},
-     {"end", (PyCFunction) match_end, METH_VARARGS},
-     {"span", (PyCFunction) match_span, METH_VARARGS},
-     {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS},
-     {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS},
-     {"expand", (PyCFunction) match_expand, METH_O},
+     {"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc},
+     {"start", (PyCFunction) match_start, METH_VARARGS, match_start_doc},
+     {"end", (PyCFunction) match_end, METH_VARARGS, match_end_doc},
+     {"span", (PyCFunction) match_span, METH_VARARGS, match_span_doc},
+     {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS,
+         match_groups_doc},
+     {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS,
+         match_groupdict_doc},
+     {"expand", (PyCFunction) match_expand, METH_O, match_expand_doc},
      {"__copy__", (PyCFunction) match_copy, METH_NOARGS},
      {"__deepcopy__", (PyCFunction) match_deepcopy, METH_O},
      {NULL, NULL}
@@@ -3613,32 -3689,32 +3653,32 @@@ static PyTypeObject Match_Type = 
      PyVarObject_HEAD_INIT(NULL,0)
      "_" SRE_MODULE ".SRE_Match",
      sizeof(MatchObject), sizeof(Py_ssize_t),
 -    (destructor)match_dealloc,        /* tp_dealloc */
 -    0,                                /* tp_print */
 -    0,                                /* tp_getattr */
 -    0,                                /* tp_setattr */
 -    0,                                /* tp_reserved */
 -    0,                                /* tp_repr */
 -    0,                                /* tp_as_number */
 -    0,                                /* tp_as_sequence */
 -    0,                                /* tp_as_mapping */
 -    0,                                /* tp_hash */
 -    0,                                /* tp_call */
 -    0,                                /* tp_str */
 -    0,                                /* tp_getattro */
 -    0,                                /* tp_setattro */
 -    0,                                /* tp_as_buffer */
 -    Py_TPFLAGS_DEFAULT,               /* tp_flags */
 -    match_doc,                        /* tp_doc */
 -    0,                                /* tp_traverse */
 -    0,                                /* tp_clear */
 -    0,                                /* tp_richcompare */
 -    0,                                /* tp_weaklistoffset */
 -    0,                                /* tp_iter */
 -    0,                                /* tp_iternext */
 -    match_methods,            /* tp_methods */
 -    match_members,            /* tp_members */
 -    match_getset,             /* tp_getset */
 +    (destructor)match_dealloc,  /* tp_dealloc */
 +    0,                          /* tp_print */
 +    0,                          /* tp_getattr */
 +    0,                          /* tp_setattr */
 +    0,                          /* tp_reserved */
 +    0,                          /* tp_repr */
 +    0,                          /* tp_as_number */
 +    0,                          /* tp_as_sequence */
 +    0,                          /* tp_as_mapping */
 +    0,                          /* tp_hash */
 +    0,                          /* tp_call */
 +    0,                          /* tp_str */
 +    0,                          /* tp_getattro */
 +    0,                          /* tp_setattro */
 +    0,                          /* tp_as_buffer */
 +    Py_TPFLAGS_DEFAULT,         /* tp_flags */
-     0,                          /* tp_doc */
++    match_doc,                  /* tp_doc */
 +    0,                          /* tp_traverse */
 +    0,                          /* tp_clear */
 +    0,                          /* tp_richcompare */
 +    0,                          /* tp_weaklistoffset */
 +    0,                          /* tp_iter */
 +    0,                          /* tp_iternext */
 +    match_methods,              /* tp_methods */
 +    match_members,              /* tp_members */
 +    match_getset,               /* tp_getset */
  };
  
  static PyObject*