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


Groups > comp.lang.python > #72890

Re: Decorating one method of a class C with another method of class C?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'arguments': 0.09; 'creation,': 0.09; 'dan': 0.09; 'subject:method': 0.09; 'cc:addr :python-list': 0.11; 'called,': 0.16; 'exactly?': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; "method's": 0.16; 'subject:class': 0.16; 'sat,': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'later': 0.20; 'seems': 0.21; 'cc:addr:python.org': 0.22; 'specify': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'apparently': 0.31; 'class': 0.32; 'subject:with': 0.35; 'something': 0.35; 'no,': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'subject:one': 0.36; 'next': 0.36; 'method': 0.36; 'subject:?': 0.36; 'information': 0.63; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=ECYdn9dcJ4a8p2CvZbtvhWijqosha1mTfwMf/y3/cfM=; b=w/dkHUyNFOGQwHf82sBjb/lHwhzebryD9BsBrqF36UgF9pSJKMAXle2H6vk/Bz3QsY quRBL5ioBsNiC6KqIzsPhj/4dtOSbeh9FUsCj01vyHzv6VQRZzqU0wDKe8PuPIywXKsI TE+ZPK0fvnb33682GIZv2ksWgGOSuskdq5KqKtX30E4mObvKYONpFu0iI757XD//vMB2 UnLKuK7LhqnZKxxjHAAhkBCLXehTkuyyncqGTFbHyz3g++9mg3dQP5UVSt11DXRrZOMf xmnMFvJBzY2XOSM/dLta/xBurJmPXeL6yp9s8y92W9nzBpJtqEEN4uHH0HIQyZmCPP7C QOkg==
MIME-Version 1.0
X-Received by 10.52.136.98 with SMTP id pz2mr8021359vdb.70.1402100433115; Fri, 06 Jun 2014 17:20:33 -0700 (PDT)
In-Reply-To <CAGGBd_pM5DGp85LVfeQgYwqS8DU8nuQL8Q8G5EzfQ5BX26fa-w@mail.gmail.com>
References <CAGGBd_pM5DGp85LVfeQgYwqS8DU8nuQL8Q8G5EzfQ5BX26fa-w@mail.gmail.com>
Date Sat, 7 Jun 2014 10:20:33 +1000
Subject Re: Decorating one method of a class C with another method of class C?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10837.1402100435.18130.python-list@python.org> (permalink)
Lines 15
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1402100435 news.xs4all.nl 2838 [2001:888:2000:d::a6]:59557
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72890

Show key headers only | View raw


On Sat, Jun 7, 2014 at 10:14 AM, Dan Stromberg <drsalists@gmail.com> wrote:
> Is there a way of decorating method1 of class C using method2 of class C?
>
> It seems like there's a chicken-and-the-egg problem; the class doesn't
> seem to know what "self" is until later in execution so there's
> apparently no way to specify @self.method2 when def'ing method1.

Since decoration happens at class creation, and arguments like self
are available only when the method's actually called, no, there's no
way you can define the method with something using information that
doesn't exist yet and may change from one call to the next :)

What are you trying to do, exactly?

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Decorating one method of a class C with another method of class C? Chris Angelico <rosuav@gmail.com> - 2014-06-07 10:20 +1000

csiph-web