Ho Nathann, On Mon, Jun 18, 2012 at 12:34:15PM +0200, Nathann Cohen wrote: > Helloooooooooo everybody !!! > > Our graph files are getting quite large, and there is in some situations a > way to make it shorter : we can define some functions in modules and import > them in the Graph class afterwards. For instance in #13073 we do > > class Graph: > ... > ... > is_weakly_chordal = sage.graphs.weakly_chordal.is_weakly_chordal > > This works well because is_weakly_chordal is defined like that : > > def is_weakly_chordal(g): > > Hence when G.is_weakly_chordal is called, "self" becomes "g" and everything > goes well. > > This, however, does not see to be possible with Cython files (if > graphs/weakly_chordal.py was graphs/weakly_chordal.pyx) and I get the > following : > > TypeError: is_weakly_chordal() takes exactly one argument (0 given) > > It looks like in this case the "self" is not given as an argument to the > function where it expects "g", and so..... it fails :-) > > Would anybody know a way around ?
This look to me like a Cython FAQ: http://wiki.cython.org/FAQ#HowdoIimplementasingleclassmethodinaCythonmodule.3F Here is the solution proposed there: import types import cython_module class A(object): pass A.method = types.MethodType(cython_module.optimized_method, None, A) Is that what you want ? Florent -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org