Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10958
| From | Eli Bendersky <eliben@gmail.com> |
|---|---|
| Date | 2011-08-06 10:34 +0300 |
| Subject | Calling super() in __init__ of a metaclass |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1962.1312616111.1164.python-list@python.org> (permalink) |
Consider this standard metaclass definition:
class MyMetaclass(type):
def __init__(cls, name, bases, dct):
super(MyMetaclass, cls).__init__(name, bases, dct)
# do meta-stuff
class Foo(object):
__metaclass__ = MyMetaclass
The call "super(MyMetaclass, cls)" should returns the parent of
MyMetaclass here. But the 'cls' passed into this __init__ is *not*
MyMetaclass, but rather the created class - i.e. Foo. So how does
"super" get to the parent of MyMetaclass using this information? The
documentation of "super" says:
If the second argument is a type, issubclass(type2, type) must be
true (this is useful for classmethods).
Yes, 'cls' is a type (it's "class Foo"), but no, it's not a subclass
of MyMetaclass, so this doesn't help.
Eli
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Calling super() in __init__ of a metaclass Eli Bendersky <eliben@gmail.com> - 2011-08-06 10:34 +0300 Re: Calling super() in __init__ of a metaclass Peter Otten <__peter__@web.de> - 2011-08-06 10:11 +0200
csiph-web