Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.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; 'example:': 0.03; '(at': 0.03; 'completeness': 0.07; 'decorator': 0.07; 'used.': 0.07; 'users,': 0.07; 'python': 0.09; 'does,': 0.09; 'least)': 0.09; 'received:155': 0.09; 'timeout': 0.09; 'def': 0.10; 'subject:not': 0.11; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'docstring': 0.16; 'email addr:functools.wraps(func)': 0.16; 'from:addr:jpmorgan.com': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'renamed': 0.16; 'securities,': 0.16; 'skip:@ 20': 0.16; 'timeout):': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.17; 'to:name:python-list@python.org': 0.20; 'sort': 0.21; 'effort.': 0.22; 'minor': 0.22; 'recognize': 0.22; 'work.': 0.23; 'received:169.254': 0.24; 'header:In-Reply-To:1': 0.25; 'setting': 0.26; 'accuracy': 0.27; 'email name:': 0.29; 'steven': 0.29; 'received:169': 0.29; 'usually': 0.30; 'function': 0.30; 'header:Received:8': 0.30; 'expect': 0.31; 'function.': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'list': 0.35; 'returning': 0.35; 'something': 0.35; 'add': 0.36; 'but': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'think': 0.40; 'your': 0.60; 'easy': 0.60; 'information,': 0.63; 'url:email': 0.63; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'goal': 0.74; 'sale': 0.76; 'loses': 0.84; 'received:169.254.8': 0.84; 'colleagues': 0.97 X-DKIM: OpenDKIM Filter v2.1.3 sz4.jpmchase.com q8ENE6QV016537 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1347664446; bh=SrC5NRWoJ0upXozD0kHxM0RpMDdWfbWR9yVKo2U8k4I=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=j2wNywpbkBgOEESGomYypo2IXSwQ8xHwvCGifIHNSAiD9oNJ+4vkQGpck9e8GjTCw Kc3bdV07oMnR6+BHrP65Dt6iUmjZj2yfHJbJdrj9DyLbFW0q0vz6DlkV3EVXb5s8Ct gj/HHDmazyM+CXBxARVAwMSRajvkl5+GKsT3cLqU= From: "Prasad, Ramit" To: "python-list@python.org" Subject: RE: Decorators not worth the effort Thread-Topic: Decorators not worth the effort Thread-Index: AQHNknv7gkzFT+MRnk+Cb3hCY/E2RZeKdLyw Date: Fri, 14 Sep 2012 23:14:00 +0000 References: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> In-Reply-To: <1017333532.1009581.1347628946603.JavaMail.root@sequans.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.47] Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes Content-Type: text/plain; charset="us-ascii" 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347664449 news.xs4all.nl 6865 [2001:888:2000:d::a6]:40640 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29194 Jean-Michel Pichavant wrote:=0D=0A=0D=0A[snip]=0D=0A=0D=0A> Ultimately, the= goal is to have something like=0D=0A> =0D=0A> @timeout(2)=0D=0A> def doAct= ion1=0D=0A> =0D=0A> @timeout(4)=0D=0A> def doAction2=0D=0A=0D=0A[snip]=0D= =0A=0D=0A> Here's Steven example:=0D=0A> =0D=0A> # Untested!=0D=0A> def tim= eout(t=3D15):=0D=0A> # Decorator factory=2E Return a decorator to actua= lly do the work=2E=0D=0A> if FPGA:=0D=0A> t *=3D 3=0D=0A> d= ef decorator(func):=0D=0A> @functools=2Ewraps(func)=0D=0A> = def inner(self, timeout):=0D=0A> self=2EsendCmd("bootMe", timeo= ut=3Dt)=0D=0A> return inner=0D=0A> return decorator=0D=0A> =0D= =0A> I can assure you, that for some python users, it's is not easy to unde= rstand=0D=0A> what it does, this function returning a function which return= s another=0D=0A> (wrapped) function=2E It requires some effort=2E=0D=0A> = =0D=0A=0D=0AI think it would help if it was renamed to set_timeout=2E And I= would =0D=0Anot expect the Python user to need to understand how it *works= *, just =0D=0Ato recognize what it *does* when it is used=2E I may not unde= rstand list's =0D=0Asort method internals (beyond the use of timsort), but = I know how to =0D=0Ause it to sort a list as I want=2E That is usually all = I need=2E=0D=0A =0D=0A=0D=0AFor example, your colleagues just need to under= stand that the below=0D=0Adecorator is setting a timeout for the function= =2E=0D=0A=0D=0A@set_timeout(min=3D15)=0D=0Adef some_function():=0D=0A ''= 'blah'''=0D=0A =0D=0A=0D=0A=0D=0AOne minor note, the style of d= ecorator you are using loses the docstring=0D=0A(at least) of the original = function=2E I would add the @functools=2Ewraps(func) =0D=0Adecorator inside= your decorator=2E=0D=0A=0D=0AThis email is confidential and subject to imp= ortant disclaimers and=0D=0Aconditions including on offers for the purchase= or sale of=0D=0Asecurities, accuracy and completeness of information, viru= ses,=0D=0Aconfidentiality, legal privilege, and legal entity disclaimers,= =0D=0Aavailable at http://www=2Ejpmorgan=2Ecom/pages/disclosures/email=2E