On Saturday, 7 June 2014 00:13:50 UTC+10, 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?
On Saturday, 7 June 2014 00:13:50 UTC+10, 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? The problem is that a partition in sage is not an isolated object, rather, it is the element class of Partitions. If you want to subclass Partition then you also need to create a parent. Also, as Nils says below you are likely to run into problems because any (most?) method(s) of MyPartition that returns a partition will return a Partition rather than a MyPartition. This said, if you really want to do this then you need something like the following: from sage.structure.element import Element from sage.structure.global_options import GlobalOptions from sage.combinat.partition import PartitionOptions class MyPartition(Partition): @staticmethod def __classcall_private__(cls, mu=None, **keyword): return MyPartitions()(super(MyPartition,cls).__classcall_private__( cls,mu,**keyword)) def fred(self): return "fred" class MyPartitions(Partitions): Element=MyPartition global_options=PartitionOptions Quite likely there will be more tweaks to get this to work fully, but it certainly gets things going: %attach mypartiiton.py sage: MyPartition([3,2]) [3, 2] sage: mu=MyPartition([3,2]).cells() sage: mu=MyPartition([3,2]).fred() -- 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 sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.