Hi Simon,
> Our current metaclasses all work by overriding a "magical" method of
> type, or adding a "magical" method to type. Ideally, this should be in
> a customisable way. In some cases, we want to override not just one
> method. Currently, each combination of customised methods requires to
> write a new metaclass. But why not have just *one* metametaclass
> "CustomisationMetaclass", such that
> CustomisationMetaclass("init","get","reduce") returns a metaclass that
> allows customisation of three methods?
Hum ! It look fun but I'm not sure it could be done without losing speed which
is IMHO critical at least for __call__.
> Syntax example:
>
> class MyClass(Parent):
> __metaclass__ = CustomisationMetaclass("call","init","add")
> @cached_function
> def __classcall__(cls, *args,**opts):
> out = type.__call__(cls, *args, **opts)
> return out
> @staticmethod
> def __classinit__(cls, *args,**opts):
> globals()[cls.__name__] = cls
> @staticmethod
> def __classadd__(cls, other):
> if cls is other:
> return cls
> return type(cls)(cls.__name__+"And"+other.__name__,
> (cls,other), {})
>
> The result would be a cached subclass of Parent that injects itself
> into global namespace (and any subclass of MyClass would do the same),
> and when adding MyClass to another class then the result would be a
> common subclass.
Just to make sure you are aware of it, ClasscallMetaclass is also used at
several places for Element and not only for Parent or Categories.
Also but this is a side discussion, I suggested to Nicolas that using a
metaclass properly, we could get rid of the '@staticmethod'. After all __new__
is never declared static or class though it is. I was close to do it in my
patch, but decided to make my change minimal.
Cheers,
Florent
--
You received this message because you are subscribed to the Google Groups
"sage-combinat-devel" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-combinat-devel?hl=en.