Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10958

Calling super() in __init__ of a metaclass

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <eliben@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '*not*': 0.05; 'type,': 0.07; "(it's": 0.09; 'subclass': 0.09; 'type)': 0.09; 'def': 0.15; 'argument': 0.15; '__init__': 0.16; 'bases,': 0.16; 'foo.': 0.16; 'metaclass': 0.16; 'subject:() ': 0.16; 'help.': 0.19; "doesn't": 0.22; 'received:209.85.212.46': 0.23; 'received:mail- vw0-f46.google.com': 0.23; '(this': 0.28; 'message- id:@mail.gmail.com': 0.29; 'second': 0.29; 'information?': 0.30; 'parent': 0.30; 'class': 0.30; 'does': 0.32; 'to:addr:python- list': 0.33; 'received:209.85.212': 0.34; 'rather': 0.35; 'created': 0.36; 'useful': 0.36; 'skip:" 10': 0.36; 'passed': 0.37; 'using': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'i.e.': 0.39; 'to:addr:python.org': 0.39; "it's": 0.40; 'here.': 0.66; 'definition:': 0.84; 'subject:Calling': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=XL7gLLf1HNpHH+ufJzevIO6WiIkkfXNv08EadIxx+Ns=; b=UK4vxMcs6TKfqqHSyjDFK9PBV8Szvc26pe3xJKoctrabGdQGp6MpOYTFrrQDDf/vAa +5+06kTvh9Zn9nTUEZDMrp4ZG33NOy5ExYGFWWw6pRkYo3OXX5mH3mMY7lbL7qTlgVoI 5yj+ooKwn9wA55qeCyUpIzXJoIwdVT2lHaZwU=
MIME-Version 1.0
From Eli Bendersky <eliben@gmail.com>
Date Sat, 6 Aug 2011 10:34:48 +0300
Subject Calling super() in __init__ of a metaclass
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1962.1312616111.1164.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1312616111 news.xs4all.nl 23904 [2001:888:2000:d::a6]:38701
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10958

Show key headers only | View raw


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 | NextNext in thread | Find similar | Unroll thread


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