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


Groups > comp.lang.python > #16979

Verbose and flexible args and kwargs syntax

Date 2011-12-11 11:49 +0100
From Eelco Hoogendoorn <hoogendoorn.eelco@gmail.com>
Subject Verbose and flexible args and kwargs syntax
Newsgroups comp.lang.python
Message-ID <mailman.3509.1323600572.27778.python-list@python.org> (permalink)

Show all headers | 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