[Python-ideas] Positional only arguments
Aaron Brady
castironpi at comcast.net
Sat May 19 04:55:49 CEST 2007
> -----Original Message-----
> From: python-ideas-bounces at python.org [mailto:python-ideas-
> bounces at python.org] On Behalf Of George Sakkis
> def foo(a, b=42, # pos-only
> % , # delimiter
> c=0, d=None, # pos-or-kw
> *args, # varargs
> e=-1,z='', # kw-only
> **kwds # keyword dictionary
> )
>
> Pros:
> - Backwards compatible: args are pos-or-kw by default as they are now;
> only those before the new delimiter are positional.
> - Easy to change the status of a parameter; just move it to the
> appropriate section (at least if it has a default value).
>
> Cons:
> - Yet another magic symbol, smells like perl (reusing the single star
> would be ambiguous).
> - The presumably common cases of functions without pos-or-kw args is
> clumsy:
> def foo(a, b, c=31, %): # all pos-only
> def bar(a, b=1, %, *, c=31, d=None): # pos-only or kw-only
>
> Overall, I still prefer the double underscores.
>
> George
>
One of the things I like about Python is we've got some extra room in the
syntax to complexify. Careful how we spend it. The extra is on a budget,
not unlimited as some things are.
def foo(a, b=42; # pos-only
c=0, d=None, # pos-or-kw
*args; # varargs
e=-1,z='', # kw-only
**kwds # keyword dictionary
)
def foo(a, b, c=31; ): # all pos-only
def bar(a, b=1;; c=31, d=None): # pos-only or kw-only
> - Yet another magic symbol, smells like perl (reusing the single star
> would be ambiguous).
True dat.
More information about the Python-ideas
mailing list