I am trying to implement an Abstract Base Class, but have hit something I 
don't understand.

I have attached a file with a minimal example of what I am trying to do.
There is an Element ABC PathTableau and a Parent ABC PathTableaux.
I then inherit from these with Element CatalanTableau and Parent 
CatalanTableaux.

PathTableau inherits from CloneableList so I want to do some preprocessing 
on the
argument before creating the object. For this minimal example I have 
removed the
methods in PathTableau.

My problem is that when I run this I get:

sage: c = CatalanTableau([0,1,0])
sage: type(c)
<class '__main__.CatalanTableaux.element_class'>

This is not what I want. I want c to be an instance of CatalanTableau
and therefore to inherit the (missing) methods from PathTableau.

I suspect it will only take a minor adjustment to get what I want but I 
don't
know what that would be.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-combinat-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-combinat-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-combinat-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-combinat-devel.
For more options, visit https://groups.google.com/d/optout.
from six import add_metaclass
from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass
from sage.misc.abstract_method import abstract_method
from sage.structure.list_clone import ClonableList
from sage.structure.unique_representation import UniqueRepresentation
from sage.structure.parent import Parent

class PathTableau(ClonableList):

    @abstract_method(optional=False)
    def check(self):
        pass

class PathTableaux(UniqueRepresentation,Parent):

    def _element_constructor_(self, ct):
        return self.element_class(self, list(ct))

@add_metaclass(InheritComparisonClasscallMetaclass)
class CatalanTableau(PathTableau):

    @staticmethod
    def __classcall_private__(cls, ot):

        w = None

        if isinstance(ot,(list,tuple)):
            try:
                w = tuple([ Integer(a) for a in ot ])
            except TypeError:
                raise ValueError("%s is not a sequence of integers." % str(ot) )

        if w == None:
            raise NotImplementedError( "Sorry; I don't know what to do with %s." % str(ot) )

        return CatalanTableaux()(w)

    def check(self):
        """
        This overwrites the abstract method.
        """
        n = len(self)
        if any(a < 0 for a in self):
           raise ValueError( "%s has a negative entry." % (str(self)) )
        for i in range(n-1):
            if abs(self[i+1]-self[i]) != 1:
                raise ValueError( "%s is not a Dyck path." % (str(self)) )

class CatalanTableaux(PathTableaux):

    Element = CatalanTableau

Reply via email to