type() of an old-style class

types.ClassType

added 2012-06-02T19:58:07Z by anders

__metaclass__

We can provide a custom metaclass by setting __metaclass__ in a class definition to any callable that takes the same arguments as type.

added 2012-06-02T19:58:07Z by anders

type(name, bases, dict) creates a new type

When the Python interpreter executes a class statement […], it calls type with the following arguments:

  • The name of the class as a string
  • A tuple of base classes - for our example this is the ‘one-pl’ 1
  • A dictionary containing members of the class (class attributes, methods, etc) mapped by their names

added 2012-06-02T19:58:07Z by anders

descriptor definition

a descriptor is an object attribute with “binding behavior”, one whose attribute access has been overridden by methods in the descriptor protocol.

added 2012-06-01T23:02:12Z by anders

non-data descriptor defnition

Descriptors that only define get are called non-data descriptors (they are typically used for methods but other uses are possible).

added 2012-06-01T23:02:12Z by anders

data descriptor definition

If an object defines both __get__ and __set__, it is considered a data descriptor.

added 2012-06-01T23:02:12Z by anders

descriptors are invoked by the __getattribute__ method

overriding __getattribute__ prevents automatic descriptor calls

added 2012-06-01T23:02:12Z by anders

descriptor precedence rules

If an instance’s dictionary has an entry with the same name as a data descriptor, the data descriptor takes precedence. If an instance’s dictionary has an entry with the same name as a non-data descriptor, the dictionary entry takes precedence.

added 2012-06-01T23:02:12Z by anders