Ask Your Question

Constructing a Ring of sets?

asked 2012-11-04 07:02:56 -0500

SLOtoSF gravatar image

updated 2012-11-08 19:32:05 -0500

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 09:05:28 -0500

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-09 20:54:04 -0500

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 10:36:11 -0500 )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 07:02:56 -0500

Seen: 95 times

Last updated: Nov 15 '12

Related questions