Special Methods for Classes.

class sage.misc.classcall_metaclass.ClasscallMetaclass(*args)

Bases: sage.misc.nested_class.NestedClassMetaclass

A metaclass providing support for special methods for classes.

From the Section Special method names of the Python Reference Manual: ‘a class cls can implement certain operations on its instances that are invoked by special syntax (such as arithmetic operations or subscripting and slicing) by defining methods with special names’. The purpose of this metaclass is to allow the class cls to implement analogues of those special methods for the operations on the class itself.

Currently, the following special methods are supported:

  • .__classcall__ (and .__classcall_private__) for customizing cls(...) (analogue of .__call__).
  • .__classget__ for customizing the binding behavior in foo.cls (analogue of .__get__).

See the documentation of __call__() and of __get__() for the description of the respective protocols.

TODO: find a good name for this metaclass.

AUTHORS:

  • Nicolas M. Thiery (2009-10) first implementation of __classcall__ and __classget__
  • Florent Hivert (2010-01): implementation of __classcall_private__, doc

Previous topic

Test for nested class Parent

Next topic

Unit testing for Sage objects

This Page