Ticket #15096: trac_15096-regexp-docstring.patch

File trac_15096-regexp-docstring.patch, 1.2 KB (added by jhpalmieri, 7 years ago)
  • sage/misc/sageinspect.py

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1383351412 25200
    # Node ID eb6b0f15f86f173e2de621a329ec71b52daaee5d
    # Parent  8377b5d138ca1db74ab7a674efc6f22a6542436f
    Introspection: display old-style docstrings correctly.
    
    diff --git a/sage/misc/sageinspect.py b/sage/misc/sageinspect.py
    a b  
    14921492        sage: sage_getdoc(f1)
    14931493        'specialised documentation\n'
    14941494
     1495    Test that old-style docstrings work -- see :trac:`15096`::
     1496
     1497        sage: f.__doc__ = 'test\n\nEXAMPLES:\n    sage: 2+2\n    4'
     1498        sage: sage_getdoc(f)
     1499        'test\n\nEXAMPLES:\n\n   sage: 2+2\n   4\n'
     1500
    14951501    AUTHORS:
    1496    
     1502
    14971503    - William Stein
    14981504    - extensions by Nick Alexander
    14991505    """
    15001506    import sage.misc.sagedoc
     1507    import re
    15011508    if obj is None: return ''
    15021509    r = _sage_getdoc_unformatted(obj)
    15031510
    15041511    if r is None:
    15051512        return ''
    15061513
     1514    M = re.search(r'(.*)(\n[ ]*)EXAMPLE(S?):[ \t]*(\2[ ]+.*)', r, re.DOTALL)
     1515    if M:
     1516        r = M.expand(r'\1\2EXAMPLES::\n\n\4')
     1517
    15071518    s = sage.misc.sagedoc.format(str(r), embedded=(embedded_override or EMBEDDED_MODE))
    15081519
    15091520    # If there is a Cython embedded position, it needs to be stripped