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


Groups > comp.lang.python > #99216

Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?)

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?)
Date Sun, 22 Nov 2015 04:02:13 +1100
Lines 14
Message-ID <mailman.41.1448125341.2291.python-list@python.org> (permalink)
References <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg@mail.gmail.com> <CAFpSVpJ1MOaH=V9wxzgzkRzrSG0YoKQk7WQ4Fo1K5fd0QLPBuQ@mail.gmail.com> <CAPTjJmpP2j4v4DiY_wdp70rcTCFkjkXpkp9J4UhDZ388Lxvq+w@mail.gmail.com> <CALwzidkaASG257RsygKUF1FRnHtttK8Q3pkvPEW34YPn80QSpg@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de 5PLvQ2h8nRHYVksjOd2OSgmc028Ey+yHyhovTzYoRshQ==
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'cc:addr:python-list': 0.09; '"if': 0.09; '22,': 0.09; 'spelled': 0.09; 'subject: \n ': 0.15; 'callable,': 0.16; 'cc:name:python': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:?)': 0.16; 'ugly.': 0.16; 'wrote:': 0.16; 'written,': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'decorator': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.27; "i'm": 0.30; 'probably': 0.31; 'implement': 0.32; 'wrap': 0.33; 'received:google.com': 0.35; 'could': 0.35; 'nov': 0.35; 'something': 0.35; 'but': 0.36; 'lines': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'front': 0.38; 'version': 0.38; 'received:209': 0.38; 'sure': 0.39; 'along': 0.39; 'subject:-': 0.39; 'default': 0.61; 'leaving': 0.63; 'chrisa': 0.84; 'to:none': 0.91
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=OcjfIuRpOBXDtHTLHBsWJpzgfZFYrFfZsT9yNssqNBQ=; b=Z2y1d9nBO+M63zHoAguA+Z9VzVTtBqs9zZ5tJ5EYvhLmKZKlTLLplHHUCw4VK7sdtY yd8WUeduIe/NFvO7nJKkaghr51C4V173/WHpks0UU7s9Pgpr2ReiJCOV9O6xcLgb1avX E8XAlinxUO0QRWahehHXvvhDuQ0ThcJi0F+VUylcV3JJB8hfhbTNmbZ3kzZFCq37vaHw w6xpADL4rCwHOnlvHG5Ei6g785eWAYZJOnIfeMFF5S3qlE+e2pQSzh2O+znIPLREQO/i uUqBzCUfUIKNS2ZQfAlSWsbZqxt6pMHjxdjbdzOXH3cr6M9FFsfL0YBtFMmfK9DymmDh eSYQ==
X-Received by 10.107.16.84 with SMTP id y81mr17546913ioi.19.1448125333613; Sat, 21 Nov 2015 09:02:13 -0800 (PST)
In-Reply-To <CALwzidkaASG257RsygKUF1FRnHtttK8Q3pkvPEW34YPn80QSpg@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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>
Xref csiph.com comp.lang.python:99216

Show key headers only | View raw


On Sun, Nov 22, 2015 at 2:01 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>> and then the decorator could wrap the function. I'm not entirely sure
>> I could implement it reliably, but even leaving that aside, having to
>> put "lambda:" in front of everything is pretty ugly.
>
> Note that "lambda: []" can also be spelled "list".

In that particular example, yes. I kept it in the large form to
maintain the parallel with the version I was quoting. But if the
decorator were to be written, it would probably be something along the
lines of "if the default is callable, do the late-binding magic", so
'list' would work just fine.

ChrisA

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


Thread

Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?) Chris Angelico <rosuav@gmail.com> - 2015-11-22 04:02 +1100

csiph-web