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


Groups > comp.lang.python > #16979

Verbose and flexible args and kwargs syntax

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <hoogendoorn.eelco@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'context': 0.04; 'dict': 0.09; 'readable': 0.09; 'subclasses': 0.09; 'thoughts?': 0.09; 'def': 0.13; '**kwargs)': 0.16; 'definition)': 0.16; 'function;': 0.16; 'pythonic': 0.16; 'received:192.168.0.11': 0.16; 'subject:syntax': 0.16; 'syntax': 0.16; 'occurred': 0.18; 'compatible': 0.21; 'pep': 0.23; 'code': 0.25; 'function': 0.27; 'for,': 0.30; 'plus,': 0.30; 'throwing': 0.30; 'certainly': 0.32; 'list': 0.32; 'idea': 0.32; 'message-id:@gmail.com': 0.33; 'header :User-Agent:1': 0.33; 'rather': 0.33; 'to:addr:python-list': 0.34; 'it.': 0.34; 'things': 0.34; 'calling': 0.34; 'forces': 0.34; 'google': 0.35; 'post': 0.36; 'but': 0.37; 'received:192': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; 'think': 0.37; 'problems': 0.37; 'could': 0.37; 'using': 0.38; 'received:192.168.0': 0.38; 'abuse': 0.39; 'finding': 0.39; 'to:addr:python.org': 0.40; 'received:192.168': 0.40; 'happens': 0.40; 'unique': 0.61; 'more': 0.61; 'forum': 0.64; 'imagine': 0.71; 'beautiful': 0.82; 'flexible,': 0.84; 'symmetry': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=BBwyusESTgY1kiJwapXJ8nJuAlgM3MjWXahy66BnDBg=; b=jpP0JoLTSKgeRLxSOgPxUcqe81WDRjZeaY4t5UtHzJtguZoGzwN1KLMTUBXfuHPdsc d5py9f/BnkwgW3zH8dtqRFcfGg2QOVuMGBspAqCcCdmnALI0m/LIIxaU0tBkchUKhoIx mxO5B+Fb3J0dKqHtsdrj3PyHzVxjob0AT1cYg=
Date Sun, 11 Dec 2011 11:49:23 +0100
From Eelco Hoogendoorn <hoogendoorn.eelco@gmail.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0
MIME-Version 1.0
To python-list@python.org
Subject Verbose and flexible args and kwargs syntax
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
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.3509.1323600572.27778.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1323600572 news.xs4all.nl 6979 [2001:888:2000:d::a6]:36632
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:16979

Show key headers only | View raw


Throwing an idea for a PEP out there:

It strikes me that the def func(*args, **kwargs) syntax is rather 
unpytonic. It certainly did not have that 'for line in file' pythonic 
obviousness for me as a beginner. Plus, asterikses are impossible to 
google for, so finding out what exactly they do more or less forces you 
to write a forum post about it.

A more readable form occurred to me, which also happens to be more 
flexible, and which I think is fully compatible with the syntax of the 
language:

def func(parg, list(args), dict(kwargs))

Perhaps this is considered abuse of notation; dict(kwargs) already has a 
meaning rather different from the one we try to give it here; but then 
again the context (being inside a function definition) is unique and 
easily recognizable.

An added advantage would be the possibility of using subclasses of dict 
and list as well; imagine how much more beautiful a lot of code would be 
if one could say

def func(attrdict(kwargs))

Problems im still wrestling with: the same syntax could not be used when 
calling a function; that lack of symmetry would make things more 
confusing, not less.

Thoughts?

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


Thread

Verbose and flexible args and kwargs syntax Eelco Hoogendoorn <hoogendoorn.eelco@gmail.com> - 2011-12-11 11:49 +0100
  Re: Verbose and flexible args and kwargs syntax Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-11 22:19 +0000

csiph-web