git grep "@add_metaclass" src/sage will give you plenty of examples on how to add metaclasses in a py3 compatible way
F Le dimanche 3 février 2019 03:41:02 UTC+1, Nathan Dunfield a écrit : > > Taking Frédéric's advice to heart, I have begun porting SnapPy to > Sage+Python3. (We have supported Python 3 outside of Sage for a few years > now.) Right now, I am having difficulty with how to register something as > a field. Below is the minimal (non) working example: if you run it with > Python 2 it will print "True", but with Python 3 you get "False". > Suggestions? > > Thanks, Nathan > > --------- > > import sage.all > from sage.structure.parent import Parent > from sage.structure.unique_representation import UniqueRepresentation > from sage.categories.fields import Fields > from sage.misc.classcall_metaclass import ClasscallMetaclass > > class SnappyNumbersMetaclass(ClasscallMetaclass): > """ > Metaclass for Sage parents of SnapPy Number objects. > """ > def __new__(mcs, name, bases, dict): > dict['category'] = lambda self : Fields() > return ClasscallMetaclass.__new__(mcs, name, bases, dict) > > class SnapPyNumbers(UniqueRepresentation, Parent): > """ > Sage parents of SnapPy Number objects. > """ > __metaclass__ = SnappyNumbersMetaclass > > def __init__(self, precision): > Parent.__init__(self) > self._precision = precision > > SPN = SnapPyNumbers(53) > print(SPN in Fields) > > -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.