property problems

Alex Martelli aleax at aleax.it
Thu Nov 14 10:04:11 EST 2002


Mike C. Fletcher wrote:

> Old style class:
> 
>      class x:
> 
> New style class:
> 
>      class x(object):
>      class y(x): # if x is defined with class x(object):
> 
> or
> 
>      class x(list):
>      class x(str):
>      class x(dict):
>      ...
> 
> That is, a new-style class is a sub-class of a new-style class.  object,
> list, str, and dict are convenient (and common) base-classes for
> new-style classes.

99.44% right.  Just one other obscure possibility:

class x:
  __metaclass__ = type


What really determines if x is a new-style class is x's metaclass,
and rather than inheriting it from x's base (which is the normal
way to do it) you may alternatively choose to assert it explicitly
by a __metaclass__ attribute in class scope (or a global variable
__metaclass__ in module scope if x has no bases).  x is new-style
iff x's metaclass is the built-in type object named 'type'.


Alex




More information about the Python-list mailing list