Changes between Initial Version and Version 1 of Ticket #21681, comment 5


Ignore:
Timestamp:
10/11/16 15:51:10 (6 years ago)
Author:
SimonKing
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #21681, comment 5

    initial v1  
    44The idea is: "metaclass used in Sage" should be synonymous to "instance (not sub-class!) of !SageMetaclass" (hence, !SageMetaclass is a metametaclass and is itself a subclass of type).
    55
    6 !SageMetaclass defines a `__call__` method for its instances (thus overriding `type.__call__`). When such instance is used as a metaclass when defining a class, then the metaclass' `__call__` method inspects the bases of the to-be-created class and dynamically creates (if necessary) a common sub-class of the metaclasses of the bases. Eventually, the class is created as an instance of the common (dynamic) metaclass. And python will be happy, because the metaclass of the new class is a sub-class of the metaclass of the given bases.
     6!SageMetaclass defines a `__call__` method for its instances (thus overriding `type.__call__`). When such instance is used as a metaclass when defining a class, then the metaclass' `__call__` method inspects the bases of the to-be-created class and dynamically creates (if necessary) a common sub-class of the metaclasses of the bases. Eventually, the class is created as an instance of the common (dynamic) metaclass. And python will be happy, because the metaclass of the new class is a sub-class of the metaclasses of the given bases.
    77
    88Both in Python 2 and in Python 3, the metaclass is called during creation of a class (which is were all magic happens). That's why I think it should work on Python 3 as well.