Ask Your Question
0

Constructing a Ring of sets?

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

SLOtoSF gravatar image

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

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
0

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

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():
            self.next = self.iterator.next()
    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
1

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

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

Comments

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

SLOtoSF gravatar imageSLOtoSF ( 2012-11-10 17:36:11 +0100 )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

Stats

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

Seen: 378 times

Last updated: Nov 15 '12

Related questions