On Friday, June 6, 2014 7:13:50 AM UTC-7, Dinakar Muthiah wrote: > > Ideally, I would like to define a subclass of Partition called MyPartition > and include all my custom methods. I think this is a standard way to extend > libraries, but for some reason this doesn't work at all. Is there a > solution that is more in the spirit of subclassing?
That tends to be a rather heavy-weight solution, which you should probably only undertake if you really want to store additional data on the objects themselves. One reason is that any routine you inherit from the superclass that produces partitions itself will not take efforts to return an instance of your subclass but will construct an instance of the original class (it can't, even if it has access to the subclass via "type(self)": instantiating new instances of the subclass may need additional data that the superclass isn't aware of!). You'd end up wrapping all those routines if you want your new instances to persist through operations. That's probably only a good design if you have good arguments why your MyPartition is a different kind of object than Partition. Using normal functions or monkey-patching them in as methods (which is only acceptable in your own private code) is going to be the easiest solution. Or edit partition.py and include your code there. Unless you get your modification accepted upstream that's going to be a rather painful solution wrt. upgrading and portability, though. -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
