Ticket #10933: trac_10933.patch

File trac_10933.patch, 1.3 KB (added by mderickx, 10 years ago)
  • sage/misc/preparser_ipython.py

    # HG changeset patch
    # User Maarten Derickx <m.derickx.student@gmail.com>
    # Date 1300811646 25200
    # Node ID 85de6a4dbdf0f33a9592a3b622798552ba9c7b3f
    # Parent  fd11c1d9fce60a6d606ca7efd4078eeda24ebf58
    #10933 make the time command also work inside function definitions
    
    diff -r fd11c1d9fce6 -r 85de6a4dbdf0 sage/misc/preparser_ipython.py
    a b  
    5656    sage.misc.interpreter.set_sage_prompt('%s'%interface_name)
    5757
    5858def preparse_ipython(line, reset=True):
     59    """
     60    TESTS:
     61       
     62        Make sure #10933 is fixed
     63       
     64    ::
     65   
     66        sage: sage.misc.preparser_ipython.preparse_ipython("def foo(str):\n   time gp(str)\n\nprint gp('1')")
     67        'def foo(str):\n   __time__=misc.cputime(); __wall__=misc.walltime(); gp(str); print "Time: CPU %.2f s, Wall: %.2f s"%(misc.cputime(__time__), misc.walltime(__wall__))\n\nprint gp(\'1\')'
     68
     69    """
    5970    global num_lines
    6071    global q_lines
    6172   
     
    7485
    7586       
    7687    if interface is None:
    77         return preparser.preparse(line, reset=reset)
     88    #We could remove do_time=True if #10933 get's fixed upstream
     89        return preparser.preparse(line, reset=reset, do_time=True)
    7890
    7991    if L.startswith('?') or L.endswith('?'):
    8092        L = L.strip('?')