Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Meta decorator with parameters, defined in explicit functions Date: Tue, 28 Jun 2016 15:02:27 +1000 Lines: 27 Message-ID: References: <85mvm5vrbw.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de PmK0mmjKGp5938EPfw4ChAB5ZgWN6VZ7Ux02CYZitfVw== Cancel-Lock: sha1:uKZ/mXSpkvPfv0bZvXPp3+irsmY= Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '*args,': 0.07; 'indeed,': 0.09; 'internally': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '\xe2\x80\x94': 0.09; 'copy-pasted': 0.16; 'lambda': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'recipe': 0.16; 'subject:parameters': 0.16; 'all,': 0.20; 'decorator': 0.22; 'explicit': 0.22; 'component': 0.23; 'header :User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; '**kwargs)': 0.29; 'clever': 0.29; 'does,': 0.29; 'url:activestate': 0.29; 'code': 0.30; 'problem': 0.33; 'common': 0.33; 'url:code': 0.34; 'gives': 0.35; 'should': 0.36; 'there': 0.36; '2005': 0.36; 'to:addr:python-list': 0.36; 'received:org': 0.37; 'doing': 0.38; 'names': 0.38; 'easily': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'bases': 0.63; 'more': 0.63; 'truth': 0.79; '_o__)': 0.84; 'decorator:': 0.84; 'expressive': 0.84; 'hunt': 0.84; 'lacks': 0.84; 'received:125': 0.84; 'understood.': 0.84; 'url:recipes': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <85mvm5vrbw.fsf@benfinney.id.au> Xref: csiph.com comp.lang.python:110646 Howdy all, I want an explicit replacement for a common decorator idiom. There is a clever one-line decorator that has been copy-pasted without explanation in many code bases for many years:: decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda func: decorator(func, *args, **kwargs) My problem with this is precisely that it is clever: it explains nothing about what it does, has many moving parts that are not named, it is non-obvious and lacks expressiveness. Even the widely-cited ActiveState recipe by Peter Hunt from 2005 gives no clue as to what this is doing internally nor what the names of its parts should be. I would like to see a more Pythonic, more explicit and expressive replacement with its component parts easily understood. -- \ “[H]ow deep can a truth be — indeed, how true can it be — if it | `\ is not built from facts?” —Kathryn Schulz, 2015-10-19 | _o__) | Ben Finney