Hi Jeroen, On 2016-10-10, Jeroen Demeyer <jdeme...@cage.ugent.be> wrote: > Maybe I'm misunderstanding you, but what I wanted to say is: Python 3 > doesn't have any place to hook a custom metaclass.
Is there a way to have a metaclass similar to our ClasscallMetaclass at all, in Python3?? I just tested, having class Classcall(type): def __call__(cls, *args, **opts): try: classcall = cls.__classcall__ except AttributeError: return type.__call__(cls, *args, **opts) return classcall(cls, *args, **opts) class MyUniqueRepresentation: __metaclass__ = Classcall @staticmethod def __classcall__(cls, *args, **opts): out = super(cls,cls).__new__(cls, *args, **opts) print("classcall got",type(out), cls) cls.__init__(out,*args,**opts) out._reduction = (type(out), args, opts) return out Loading the above into python2, I get >>> class Foo(MyUniqueRepresentation): ... def __init__(self, a,b): ... self.a = a ... self.b = b ... >>> A = Foo("A","B") ('classcall got', <class '__main__.Foo'>, <class '__main__.Foo'>) >>> A._reduction (<class '__main__.Foo'>, ('A', 'B'), {}) But doing the same in python3, it gives >>> class Foo(MyUniqueRepresentation): ... def __init__(self, a,b): ... self.a = a ... self.b = b ... >>> A = Foo("A","B") >>> A._reduction Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'Foo' object has no attribute '_reduction' So, in python2, the __classcall__ is called, in python3 it isn't. What needs to be done to make the above example work in python3? It makes me wonder: IIRC there are people trying to build SageMath with python3 (that's why I put sage-devel on Cc). Does UniqueRepresentation actually work with python3, when the metaclass apparently is not called during creation of a class? Best regards, Simon -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.