# 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): 
1033  1033  sage: sage.misc.sageinspect.sage_getargspec(foo) 
1034  1034  ArgSpec(args=['x', 'a', 'b'], varargs=None, keywords=None, defaults=('\')"', {False: 'bar'})) 
1035  1035  
 1036  The following produced a syntax error before the patch at :trac:`11913`:: 
 1037  
 1038  sage: sage.misc.sageinspect.sage_getargspec(r.lm) 
 1039  
1036  1040  AUTHORS: 
1037  1041  
1038  1042   William Stein: a modified version of inspect.getargspec from the 
… 
… 
def sage_getargspec(obj): 
1060  1064  source = sage_getsource(obj) 
1061  1065  # we try to find the definition and parse it by _sage_getargspec_ast 
1062  1066  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 
1064  1072  elif isinstance(obj,functools.partial): 
1065  1073  base_spec = sage_getargspec(obj.func) 
1066  1074  return base_spec 