Ask Your Question

Constructing a Ring of sets?

asked 2012-11-04 14:02:56 +0200

SLOtoSF gravatar image

updated 2012-11-09 02:32:05 +0200

How can I create a class which derives from RingElement and Set?

It seems I get the standard:

TypeError: Error when calling the metaclass bases
    multiple bases have instance lay-out conflict
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-11-15 16:05:28 +0200

SLOtoSF gravatar image

After implementing @burcin's advice, and getting help from another friend, I found this to be a really good way to get set-like behavior from any SageObject:

class ActsLikeASetButIsntASet(SageObject):
    def __init__(self,_set):
        self.values = _set
        self.iterator = self.__iter__()
        if self.values != set():
    def __iter__(self):
        for this_entry in self.values:
            yield this_entry
    def get_set(self):
        return set(self.values)
    def __repr__(self):
        return str(list(self.values))
    def __getattr__(self,attr):
        return getattr(self.values,attr)
edit flag offensive delete link more

answered 2012-11-10 03:54:04 +0200

Cython does not support multiple inheritance. Both RingElement and Set_object (latter a subclass of Set_generic) are Cython classes, so you cannot derive from them at the same time.

I suggest subclassing only RingElement and keeping a member variable of type Set_object. You can use __getattr__, __setattr__ tricks to make your object still behave like an instance of Set_object.

edit flag offensive delete link more


@burcin, Thanks, this is exactly what I've been needing and it's working.

SLOtoSF gravatar imageSLOtoSF ( 2012-11-10 17:36:11 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-11-04 14:02:56 +0200

Seen: 278 times

Last updated: Nov 15 '12

Related questions