Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16983
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!xlned.com!feeder3.xlned.com!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| 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; 'operator': 0.04; 'instance,': 0.05; 'run-time': 0.05; 'python': 0.08; 'args,': 0.09; 'curious.': 0.09; 'dict': 0.09; 'foo': 0.09; 'positional': 0.09; 'subclass': 0.09; 'subclasses': 0.09; 'def': 0.13; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; 'argument': 0.15; 'args"': 0.16; 'eliminating': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; "function's": 0.16; 'irrelevant,': 0.16; 'issue:': 0.16; 'lookup': 0.16; 'php:': 0.16; 'pythonic': 0.16; 'read?': 0.16; 'subclasses.': 0.16; 'subject:syntax': 0.16; '\xa0def': 0.16; 'syntax': 0.16; 'language': 0.17; 'wrote:': 0.18; 'arguments': 0.18; 'instance': 0.18; 'suggest': 0.20; 'dec': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'thus': 0.23; 'breaks': 0.23; 'replacing': 0.23; 'keyword': 0.24; 'variable': 0.28; 'compare': 0.28; 'message-id:@mail.gmail.com': 0.28; 'pm,': 0.29; 'class': 0.29; 'booth': 0.30; 'keywords,': 0.30; 'sun,': 0.30; 'syntax,': 0.30; 'typeerror:': 0.30; 'chris': 0.30; "i've": 0.31; 'quite': 0.32; 'list': 0.32; "can't": 0.32; 'actually': 0.33; 'rather': 0.33; 'that,': 0.33; 'done': 0.34; 'to:addr :python-list': 0.34; 'two': 0.37; 'but': 0.37; 'received:google.com': 0.37; "there's": 0.37; 'another': 0.37; 'think': 0.37; 'could': 0.37; 'doing': 0.38; 'using': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'being': 0.39; 'else': 0.39; 'why': 0.39; "it's": 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'happens': 0.40; 'personal': 0.60; 'more': 0.61; '2011': 0.61; 'matter': 0.61; '11,': 0.68; 'symmetry': 0.84; 'symmetry,': 0.84; 'worthwhile.': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=gNHx0Ixf1e25o1oJpiRJmx2xC3wEMyp+aYd+S6VwYzU=; b=YrOVT8Phu67YxxRAFD9gv1/RdMkR5GF4lqsntl125qXaFYqtdbBzfazURpjIv4Uotu QxygFIlGpxG9fiY8s8Z5XcrtVITPSYszEqN6H8I97JWnaM5M6Ye1cocFd/TsSLtBf3Ri M8aMIqFO4lhRuos+z03N1JMzdOBtY+hsKg6Tk= |
| MIME-Version | 1.0 |
| In-Reply-To | <Xns9FB880CEA6F2Fduncanbooth@127.0.0.1> |
| References | <4EE48AB3.7070807@gmail.com> <mailman.3510.1323602145.27778.python-list@python.org> <Xns9FB880CEA6F2Fduncanbooth@127.0.0.1> |
| Date | Mon, 12 Dec 2011 00:09:56 +1100 |
| Subject | Re: Verbose and flexible args and kwargs syntax |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3511.1323608999.27778.python-list@python.org> (permalink) |
| Lines | 63 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1323608999 news.xs4all.nl 6922 [2001:888:2000:d::a6]:56371 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:16983 |
Show key headers only | View raw
On Sun, Dec 11, 2011 at 11:39 PM, Duncan Booth
<duncan.booth@invalid.invalid> wrote:
> Chris Angelico <rosuav@gmail.com> wrote:
> If it used keywords then you could keep symmetry quite easily:
>
> def anyargs(arglist args, argdict kwargs):
> return wrappedfunc(arglist args, argdict kwargs)
>
> and you would have the advantage of two new keywords that people could
> actually search on.
Yes, that's just a strict keywordification of the * and ** symbols.
The same argument could be made for eliminating the standard algebraic
+ operator and replacing it with a keyword "__add__". I don't think
that's worthwhile.
The OP suggested using 'dict' and 'list' themselves as the keywords,
thus allowing the use of subclasses. This would make it unsearchable,
or else rather verbose:
def anyargs(pack list args, pack dict kwargs):
return wrappedfunc(pack list args, pack dict kwargs)
With this syntax, what happens if you muck up list/dict? Or
alternatively, the briefer syntax:
def anyargs(pack list args, pack dict kwargs):
return wrappedfunc(pack args, pack kwargs)
which breaks the symmetry, and doesn't say which one you're doing -
for instance, if you only use one out of list and dict args, it would
make sense to have a variable "options" or "args" that gets unpacked
to the function's arguments - and there's no way to see whether it's
going to be keyword or positional.
The verbose syntax has a lot going for it, but it's rather verbose.
Why say "pack list args" when you can just say "*args"? Compare
initializer syntax between Python and PHP:
foo = ["asdf", "qwer", {1:2, 3:4}]
$foo = array("asdf", "qwer", array(1=>2, 3=>4))
Is it more Pythonic to use explicitly-named types, or to have simple
notation that's clear and easy to read? Or is this a matter for
personal preference?
>> Another issue: You suggest being able to use "attrdict" or some other
>> dict subclass. This means that, rather than being a language
>> construct, this will involve a name lookup. And what happens if you
>> have a class that subclasses both list and dict? Will it get the
>> positional args, the keyword args, or both?
>
> Irrelevant, you can't subclass both list and dict:
> TypeError: multiple bases have instance lay-out conflict
Ah. Curious. I've not done much with multiple inheritance in Python
(come to think of it, I don't recall when I last used MI in _any_
language). In any case, there's still the potential unclarity as to
_which_ of dict and list is the one that's been inherited, which
requires a run-time lookup to solve.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Verbose and flexible args and kwargs syntax Chris Angelico <rosuav@gmail.com> - 2011-12-11 22:15 +1100
Re: Verbose and flexible args and kwargs syntax Duncan Booth <duncan.booth@invalid.invalid> - 2011-12-11 12:39 +0000
Re: Verbose and flexible args and kwargs syntax Chris Angelico <rosuav@gmail.com> - 2011-12-12 00:09 +1100
Re: Verbose and flexible args and kwargs syntax Christian Heimes <lists@cheimes.de> - 2011-12-11 14:14 +0100
csiph-web