policy concerning __classcall_private__ and __init__: who does the input checking

7 views
Skip to first unread message

Martin R

unread,
4:32 AM (5 hours ago) 4:32 AM
to sage-devel
Dear all,

is my understanding correct?

    in general, __classcall_private__ should do input validation and normalization, and call the _element_constructor_ of the correct parent, whereas __init__ should just do the object initialization.

For example, DyckWord does precisely that.  On the other hand, Core has almost identical __classcall_private__ and __init__:

    @staticmethod
    def __classcall_private__(cls, part, k):
...
        if isinstance(part, cls):
            return part
        part = Partition(part)
        if not part.is_core(k):
            raise ValueError("%s is not a %s-core" % (part, k))
        l = sum(part.k_boundary(k).row_lengths())
        return Cores(k, l)(part)

    def __init__(self, parent, core):
...
        k = parent.k
        part = Partition(core)
        if not part.is_core(k):
            raise ValueError("%s is not a %s-core" % (part, k))
        CombinatorialElement.__init__(self, parent, core)

Permutation does a mix of things, but the checking part can be switched off by passing check=False.

Martin
Reply all
Reply to author
Forward
0 new messages