Is there a way to ask a class what its metaclasses are ?
Terry Reedy
tjreedy at udel.edu
Mon Feb 23 12:29:16 EST 2009
Barak, Ron wrote:
>
> When I try the following (to see the types of the classes involved):
>
> #!/usr/bin/env python
>
> import wx
> from Debug import _line as line
>
> class CopyAndPaste(object):
> def __init__(self, *args, **kwargs):
> super(CopyAndPaste, self).__init__(*args, **kwargs)
> print line()+". type(wx.Frame):",type(wx.Frame)
> print line()+". type(object):",type(object)
>
> I get:
>
> $ python -u CopyAndPaste.py
> 9. type(wx.Frame): <type 'type'>
> 10. type(object): <type 'type'>
>
> And I don't understand what it means...
The default metaclass is named 'type'. It it the class of all builtin
classes and all user classes (3.0) that do not specify otherwise.
Behind the scenes, new user classes are created as instances of 'type'
by the equivalent of 'type(name, bases, class_dict)'. What is possibly
confusing is that the __call__ method of 'type' also allows calls to
type with only one arg, in which case it returns the class of the arg
instead of trying to create a new class. And so one might mistakenly
think that 'type' is a built-in function rather than a class.
Terry Jan Reedy
More information about the Python-list
mailing list