First time here? Check out the FAQ!

Ask Your Question
0

Constructing a Ring of sets?

asked 12 years ago

SLOtoSF gravatar image

updated 12 years ago

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
Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered 12 years ago

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)
Preview: (hide)
link
1

answered 12 years ago

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.

Preview: (hide)
link

Comments

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

SLOtoSF gravatar imageSLOtoSF ( 12 years ago )

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: 12 years ago

Seen: 404 times

Last updated: Nov 15 '12

Related questions