Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.04; 'subject:Python': 0.06; 'correct,': 0.09; 'definition,': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'function,': 0.09; 'instance.': 0.09; 'lookup': 0.09; 'message-id:@stoneleaf.us': 0.09; 'resolved,': 0.09; 'subject:method': 0.09; 'subject:set': 0.09; 'yeah,': 0.09; '~ethan~': 0.09; "wouldn't": 0.14; '+1.': 0.16; '10:59': 0.16; 'descriptor': 0.16; 'factory,': 0.16; 'op.': 0.16; 'overriding': 0.16; 'subject:Dev': 0.16; 'wrote:': 0.18; 'subject:] ': 0.20; '>>>': 0.22; 'creating': 0.23; 'header:User- Agent:1': 0.23; 'instance,': 0.24; 'looks': 0.24; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'correct': 0.29; 'possibility': 0.29; '>>>>': 0.31; 'though.': 0.31; 'writes:': 0.31; 'class': 0.32; 'implemented': 0.33; 'maybe': 0.34; 'really': 0.36; 'method': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'either': 0.39; 'john': 0.61; 'received:173': 0.61; 'real': 0.63; 'different': 0.65; 'within': 0.65; 'ethan': 0.84; 'furman': 0.84; 'positively': 0.84; 'absolutely': 0.87 Date: Sat, 08 Nov 2014 11:49:17 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: [Python-Dev] Dinamically set __call__ method References: <545919B6.7040007@stoneleaf.us> <87a943qyvn.fsf@handshake.de> <545CC204.2010301@stoneleaf.us> <8761eq424e.fsf@handshake.de> In-Reply-To: <8761eq424e.fsf@handshake.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415476169 news.xs4all.nl 2944 [2001:888:2000:d::a6]:56051 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80402 On 11/07/2014 10:50 PM, dieter wrote: > Ethan Furman writes: > >> On 11/06/2014 10:59 PM, dieter wrote: >>> John Ladasky writes: >>>> On Tuesday, November 4, 2014 11:12:31 AM UTC-8, Ethan Furman wrote: >>>> >>>>> If you really absolutely positively have to have the signature be correct for each instance, you may to either look at a >>>>> function creating factory, a class creating factory, or a meta-class. >>>> >>>> +1. Overriding __call__() within the class definition, over and over again, with different function, looks awkward to me. >>> >>> A possibility to get the original approach implemented looks like: >>> >>> make "__call__" a descriptor on the class which looks up the real >>> method on the instance. >> >> This still wouldn't get the signatrue correct, though. > > Why not? Once the descriptor is resolved, you get the final > instance method - with the correct signature. Hmmm... well, it wouldn't be correct on a class lookup, but, yeah, it would be correct for an instance lookup -- and maybe that's good enough for the OP. -- ~Ethan~