Fernando, I just implemented "??" source code introspection for Pyrex-defined function for SAGE. E.g., one can now do this:
sage: n = Mod(3,7) # a Pyrex extension class sage: n.is_zero?? Type: builtin_function_or_method Base Class: <type 'builtin_function_or_method'> String Form: <built-in method is_zero of sage.rings.integer_mod.IntegerMod_int object at 0x8cb0440> Namespace: Interactive Source: File: /Volumes/HOME/s/local/lib/python/site-packages/sage/rings/integer_mod.pyx def is_zero(IntegerMod_int self): """ Returns \\code{True} if this is $0$, otherwise \\code{False}. EXAMPLES: sage: mod(13,5).is_zero() False sage: mod(25,5).is_zero() True """ return bool(self.ivalue == 0) --------------- Unfortunately, it is necessary to very slightly modify IPython. In particular, currently there is currently no analgoue of IPython.OInspect.getdoc = my_getdoc for getting the source file. I.e., I want to be able to do something like IPython.OInspect.inspect_getsource = my_getsource Unfortunately, IPython gets source very deeply in very big functions by calling inspect.getsource, but I shouldn't reassign inspect.getsource. Instead, if you replace your calls to inspect.getsource with calls to a function inspect_getsource, IPython works exactly as before, except it's possible to reassign at startup how IPython gets source of an object. Here's a udiff that does it. diff -r c08d68b9bc57 OInspect.py --- a/OInspect.py Wed Oct 25 02:33:13 2006 -0500 +++ b/OInspect.py Wed Oct 25 02:33:33 2006 -0500 @@ -37,6 +37,9 @@ from IPython.Itpl import itpl from IPython.Itpl import itpl from IPython.wildcard import list_namespace from IPython.ColorANSI import * + +def inspect_getsource(x): + return inspect.getsource(x) #**************************************************************************** # HACK!!! This is a crude fix for bugs in python 2.3's inspect module. We @@ -262,11 +265,12 @@ class Inspector: # Flush the source cache because inspect can return out-of-date source linecache.checkcache() try: - src = inspect.getsource(obj) + src = inspect_getsource(obj) except: self.noinfo('source',oname) else: page(self.format(src)) + def pfile(self,obj,oname=''): """Show the whole file where an object was defined.""" @@ -402,11 +406,10 @@ class Inspector: linecache.checkcache() source_success = False try: - if not binary_file: - source = self.format(inspect.getsource(obj)) - out.write(header('Source:\n')+source.rstrip()) - source_success = True - except: + source = self.format(inspect_getsource(obj)) + out.write(header('Source:\n')+source.rstrip()) + source_success = True + except Exception, msg: pass if ds and not source_success: --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---