On Sunday, November 6, 2016 at 3:12:38 PM UTC-8, Salvatore Stella wrote: > > {{{ > if n == 2 and m == 0: > self.greedy_element = MethodType(greedy_element, self, self.__class__) > }}} > > This has at least one drawback: the documentation produced by Sphinx looks > weird because these methods appears as functions outside the scope of the > class. Furthermore is not very readable and subsequently harder to debug. >
Why not just make a subclass for the n==2, m==0 case and put the methods there? Just make sure that your parent class knows which class to instantiate for its elements. Having implemented this one may be interested in calling `change_me` on the > entries of a list. Sometime such a list may not be specified explicitly > but > might be computed from some description or from some other data. In short > one > would like to preparse the input of `change_me` before calling the > original > functions. Now this preparsing is identical for both classes. To avoid > duplicated code we made a wrapper that takes care of the preparsing and we > used it in both classes. So far so good. The problems starts when writing > the > documentation for this setup. Right now each `change_me` only has the > documentation regarding the integer input. All the other possibilities are > in > the documentation of the wrapper. Moreover the wrapper changes on the fly > the > documentation of `change_me` to add the relevant extra possibilities and > make > them available from the inline help. > This again sounds like a scenario that fits perfectly in a class hierarchy with inheritance: Implement your wrapper in an appropriate superclass and let it dispatch to "change_me" on the object it is acting on. For documentation: just document the "wrapper" appropriately: put everything there that a user needs. I fail to see from what you describe why your wrapper needs to "change on the fly". That sounds like something that is best avoided. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.