Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(python': 0.07; 'lines,': 0.07; 'decorator': 0.09; 'mess': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:method': 0.09; 'suggestions.': 0.09; 'def': 0.12; 'jan': 0.12; '2.7': 0.14; '3.3,': 0.16; 'old- style': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject: \n ': 0.16; 'subject:make': 0.16; 'subject:possible': 0.16; 'thursday,': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'header:User- Agent:1': 0.23; 'sorry,': 0.24; 'class.': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'class': 0.32; 'know.': 0.32; 'subject:from': 0.34; 'could': 0.34; 'classes': 0.35; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'instances': 0.36; 'skip:f 40': 0.36; 'method': 0.36; 'to:addr :python-list': 0.38; 'pm,': 0.38; "couldn't": 0.39; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'august': 0.61; 'received:173': 0.61; 'email addr:gmail.com': 0.63; 'name': 0.63; 'received:fios.verizon.net': 0.84; 'thereof': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Is it possible to make a unittest decorator to rename a method from "x" to "testx?" Date: Thu, 08 Aug 2013 15:28:40 -0400 References: <215331fa-379f-4251-b722-44555349fbb5@googlegroups.com> <292722f2-56a7-4a9d-a3ad-e65b44cac834@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 In-Reply-To: <292722f2-56a7-4a9d-a3ad-e65b44cac834@googlegroups.com> 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375990134 news.xs4all.nl 15955 [2001:888:2000:d::a6]:54303 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52221 On 8/8/2013 12:20 PM, adam.preble@gmail.com wrote: > On Thursday, August 8, 2013 3:04:30 AM UTC-5, Terry Reedy wrote: >> def test(f): >> >> f.__class__.__dict__['test_'+f.__name__] Sorry, f.__class__ is 'function', not the enclosing class. A decorator for a method could not get the enclosing class name until 3.3, when it would be part of f.__qualname__. Use one of the other suggestions. > Just for giggles I can mess around with those exact lines, but I did get spanked trying to do something similar. I couldn't reference __class__ for some reason (Python 2.7 problem?). In 2.x, old-style classes and instances thereof do not have .__class__. All other objects do, as far as I know. -- Terry Jan Reedy