Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33647
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.011 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'subject:skip:t 10': 0.07; 'type,': 0.07; '__init__': 0.09; 'imply': 0.09; 'subject:method': 0.09; 'def': 0.10; '__new__': 0.16; 'called,': 0.16; 'foo()': 0.16; 'self)': 0.16; 'wrote:': 0.17; 'instance': 0.17; '>>>': 0.18; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'right.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'skip:_ 10': 0.29; 'class': 0.29; 'classes': 0.30; 'received:209.85.215.46': 0.30; 'instances': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'self': 0.34; 'nov': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'method': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; '20,': 0.65; 'subject:The': 0.71; 'manages': 0.84; 'subject:calls': 0.84; 'to:name:python': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=nsRUvKpl0ZgyiwkTaCEXiEov93VPjOwHEDzw/ZDjMCw=; b=sbAkzyc67jRQxAUNAHGfF8QF+smS7yyq+k1WgA97Np9k3M3YiYEruJJdrO65gSgNhA 4cv7M4vUfD8kpNWj7fV0dLErkAm05AUDggiWJNCRypzHsdvydiTZhHCTALc+mL+fxhJq 6UA3imRgoIH1bFU4wCsJZKi3jQzctrDRZh2/3drTRpUCGqmkyS2vDbf/lrChVHVIiH/w v2/Pjkm5h/RORse/da3Y0ecjCmxvOO790EqXVBPadVzAgRS+pQvvq4xUTOJ7ZwkP2PMB BlItb7G0z8gMw7w1LNaRAjIf9U+0hUtdfgA2MMcVvyzX8x0Fn+tweEPyYTuRhZ7badDv 9k7w== |
| MIME-Version | 1.0 |
| In-Reply-To | <k8gekt$n48$1@speranza.aioe.org> |
| References | <k8gekt$n48$1@speranza.aioe.org> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Tue, 20 Nov 2012 12:25:08 -0700 |
| Subject | Re: The type.__call__() method manages the calls to __new__ and __init__? |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.80.1353439541.29569.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1353439541 news.xs4all.nl 6898 [2001:888:2000:d::a6]:48101 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:33647 |
Show key headers only | View raw
On Tue, Nov 20, 2012 at 10:29 AM, Marco <name.surname@gmail.com> wrote:
> Because when I call an instance the __call__ method is called, and because
> the classes are instances of type, I thought when I call a Foo class this
> imply the call type.__call__(Foo), and so this one manages the Foo.__new__
> and Foo.__init__ calls:
Yes, that's right. Observe:
>>> class MetaFoo(type):
... def __call__(cls):
... print("before")
... self = super().__call__()
... print("after", self)
... return self
...
>>> class Foo(metaclass=MetaFoo):
... def __new__(cls):
... print("__new__")
... return super().__new__(cls)
... def __init__(self):
... print("__init__")
...
>>> f = Foo()
before
__new__
__init__
after <__main__.Foo object at 0x00C55410>
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
The type.__call__() method manages the calls to __new__ and __init__? Marco <name.surname@gmail.com> - 2012-11-20 18:29 +0100 Re: The type.__call__() method manages the calls to __new__ and __init__? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-20 12:25 -0700
csiph-web