Ticket #11913: trac_11913-sage.patch

File trac_11913-sage.patch, 1.6 KB (added by jhpalmieri, 9 years ago)

Sage library

  • sage/misc/sageinspect.py

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1339623857 25200
    # Node ID 3b9b90fa0581c01c7b75bb27875d4fb374551981
    # Parent  d6643504ea507b36d24058701f91eac791ceb855
    Fix sage_getargspec on objects from the R library, e.g. r.lm.
    Before this patch, calling sage_getargspec on r.lm would lead
    to a syntax error; now it returns None. (The syntax error could
    then break introspection on r.lm in the notebook.)
    
    diff --git a/sage/misc/sageinspect.py b/sage/misc/sageinspect.py
    a b def sage_getargspec(obj): 
    10331033        sage: sage.misc.sageinspect.sage_getargspec(foo)
    10341034        ArgSpec(args=['x', 'a', 'b'], varargs=None, keywords=None, defaults=('\')"', {False: 'bar'}))
    10351035
     1036    The following produced a syntax error before the patch at :trac:`11913`::
     1037
     1038        sage: sage.misc.sageinspect.sage_getargspec(r.lm)
     1039
    10361040    AUTHORS:
    10371041   
    10381042    - William Stein: a modified version of inspect.getargspec from the
    def sage_getargspec(obj): 
    10601064            source = sage_getsource(obj)
    10611065            # we try to find the definition and parse it by _sage_getargspec_ast
    10621066            proxy = 'def dummy' + _grep_first_pair_of_parentheses(source) + ':\n    return'
    1063             return _sage_getargspec_from_ast(proxy)
     1067            try:
     1068                return _sage_getargspec_from_ast(proxy)
     1069            except SyntaxError:
     1070                # To fix trac #10860. See #11913 for more information.
     1071                return None
    10641072        elif isinstance(obj,functools.partial):
    10651073            base_spec = sage_getargspec(obj.func)
    10661074            return base_spec