[Python-checkins] cpython: #19639: update the repr of the match objects in the docs. Patch by Claudiu

ezio.melotti python-checkins at python.org
Sat Nov 23 19:27:43 CET 2013


http://hg.python.org/cpython/rev/bbfc559f7190
changeset:   87440:bbfc559f7190
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Sat Nov 23 20:27:27 2013 +0200
summary:
  #19639: update the repr of the match objects in the docs.  Patch by Claudiu Popa.

files:
  Doc/howto/regex.rst     |  16 ++++++++--------
  Doc/library/fnmatch.rst |   2 +-
  Doc/library/re.rst      |  18 +++++++++---------
  3 files changed, 18 insertions(+), 18 deletions(-)


diff --git a/Doc/howto/regex.rst b/Doc/howto/regex.rst
--- a/Doc/howto/regex.rst
+++ b/Doc/howto/regex.rst
@@ -402,7 +402,7 @@
 
    >>> m = p.match('tempo')
    >>> m  #doctest: +ELLIPSIS
-   <_sre.SRE_Match object at 0x...>
+   <_sre.SRE_Match object; span=(0, 5), match='tempo'>
 
 Now you can query the :ref:`match object <match-objects>` for information
 about the matching string.  :ref:`match object <match-objects>` instances
@@ -441,7 +441,7 @@
    >>> print(p.match('::: message'))
    None
    >>> m = p.search('::: message'); print(m)  #doctest: +ELLIPSIS
-   <_sre.SRE_Match object at 0x...>
+   <_sre.SRE_Match object; span=(4, 11), match='message'>
    >>> m.group()
    'message'
    >>> m.span()
@@ -493,7 +493,7 @@
    >>> print(re.match(r'From\s+', 'Fromage amk'))
    None
    >>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998')  #doctest: +ELLIPSIS
-   <_sre.SRE_Match object at 0x...>
+   <_sre.SRE_Match object; span=(0, 5), match='From '>
 
 Under the hood, these functions simply create a pattern object for you
 and call the appropriate method on it.  They also store the compiled
@@ -685,7 +685,7 @@
    line, the RE to use is ``^From``. ::
 
       >>> print(re.search('^From', 'From Here to Eternity'))  #doctest: +ELLIPSIS
-      <_sre.SRE_Match object at 0x...>
+      <_sre.SRE_Match object; span=(0, 4), match='From'>
       >>> print(re.search('^From', 'Reciting From Memory'))
       None
 
@@ -697,11 +697,11 @@
    or any location followed by a newline character.     ::
 
       >>> print(re.search('}$', '{block}'))  #doctest: +ELLIPSIS
-      <_sre.SRE_Match object at 0x...>
+      <_sre.SRE_Match object; span=(6, 7), match='}'>
       >>> print(re.search('}$', '{block} '))
       None
       >>> print(re.search('}$', '{block}\n'))  #doctest: +ELLIPSIS
-      <_sre.SRE_Match object at 0x...>
+      <_sre.SRE_Match object; span=(6, 7), match='}'>
 
    To match a literal ``'$'``, use ``\$`` or enclose it inside a character class,
    as in  ``[$]``.
@@ -726,7 +726,7 @@
 
       >>> p = re.compile(r'\bclass\b')
       >>> print(p.search('no class at all'))  #doctest: +ELLIPSIS
-      <_sre.SRE_Match object at 0x...>
+      <_sre.SRE_Match object; span=(3, 8), match='class'>
       >>> print(p.search('the declassified algorithm'))
       None
       >>> print(p.search('one subclass is'))
@@ -744,7 +744,7 @@
       >>> print(p.search('no class at all'))
       None
       >>> print(p.search('\b' + 'class' + '\b'))  #doctest: +ELLIPSIS
-      <_sre.SRE_Match object at 0x...>
+      <_sre.SRE_Match object; span=(0, 7), match='\x08class\x08'>
 
    Second, inside a character class, where there's no use for this assertion,
    ``\b`` represents the backspace character, for compatibility with Python's
diff --git a/Doc/library/fnmatch.rst b/Doc/library/fnmatch.rst
--- a/Doc/library/fnmatch.rst
+++ b/Doc/library/fnmatch.rst
@@ -86,7 +86,7 @@
       '.*\\.txt$'
       >>> reobj = re.compile(regex)
       >>> reobj.match('foobar.txt')
-      <_sre.SRE_Match object at 0x...>
+      <_sre.SRE_Match object; span=(0, 10), match='foobar.txt'>
 
 
 .. seealso::
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -755,7 +755,7 @@
 
    >>> pattern = re.compile("d")
    >>> pattern.search("dog")     # Match at index 0
-   <_sre.SRE_Match object at ...>
+   <_sre.SRE_Match object; span=(0, 1), match='d'>
    >>> pattern.search("dog", 1)  # No match; search doesn't include the "d"
 
 
@@ -772,7 +772,7 @@
    >>> pattern = re.compile("o")
    >>> pattern.match("dog")      # No match as "o" is not at the start of "dog".
    >>> pattern.match("dog", 1)   # Match as "o" is the 2nd character of "dog".
-   <_sre.SRE_Match object at ...>
+   <_sre.SRE_Match object; span=(1, 2), match='o'>
 
    If you want to locate a match anywhere in *string*, use
    :meth:`~regex.search` instead (see also :ref:`search-vs-match`).
@@ -1139,7 +1139,7 @@
 
    >>> re.match("c", "abcdef")  # No match
    >>> re.search("c", "abcdef") # Match
-   <_sre.SRE_Match object at ...>
+   <_sre.SRE_Match object; span=(2, 3), match='c'>
 
 Regular expressions beginning with ``'^'`` can be used with :func:`search` to
 restrict the match at the beginning of the string::
@@ -1147,7 +1147,7 @@
    >>> re.match("c", "abcdef")  # No match
    >>> re.search("^c", "abcdef") # No match
    >>> re.search("^a", "abcdef")  # Match
-   <_sre.SRE_Match object at ...>
+   <_sre.SRE_Match object; span=(0, 1), match='a'>
 
 Note however that in :const:`MULTILINE` mode :func:`match` only matches at the
 beginning of the string, whereas using :func:`search` with a regular expression
@@ -1155,7 +1155,7 @@
 
    >>> re.match('X', 'A\nB\nX', re.MULTILINE)  # No match
    >>> re.search('^X', 'A\nB\nX', re.MULTILINE)  # Match
-   <_sre.SRE_Match object at ...>
+   <_sre.SRE_Match object; span=(4, 5), match='X'>
 
 
 Making a Phonebook
@@ -1274,9 +1274,9 @@
 functionally identical:
 
    >>> re.match(r"\W(.)\1\W", " ff ")
-   <_sre.SRE_Match object at ...>
+   <_sre.SRE_Match object; span=(0, 4), match=' ff '>
    >>> re.match("\\W(.)\\1\\W", " ff ")
-   <_sre.SRE_Match object at ...>
+   <_sre.SRE_Match object; span=(0, 4), match=' ff '>
 
 When one wants to match a literal backslash, it must be escaped in the regular
 expression.  With raw string notation, this means ``r"\\"``.  Without raw string
@@ -1284,9 +1284,9 @@
 functionally identical:
 
    >>> re.match(r"\\", r"\\")
-   <_sre.SRE_Match object at ...>
+   <_sre.SRE_Match object; span=(0, 1), match='\\'>
    >>> re.match("\\\\", r"\\")
-   <_sre.SRE_Match object at ...>
+   <_sre.SRE_Match object; span=(0, 1), match='\\'>
 
 
 Writing a Tokenizer

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list