[Python-3000] Pronouncement on parameter lists
Guido van Rossum
guido at python.org
Fri Apr 21 20:22:19 CEST 2006
On 4/21/06, Jim Jewett <jimjjewett at gmail.com> wrote:
> On 4/21/06, Alex Martelli <aleaxit at gmail.com> wrote:
> > On 4/21/06, Guido van Rossum <guido at python.org> wrote:
> > > To prevent more abominations like this, let me pronounce that I now
> > > like the single-star syntax:
> > > def foo(a, b, *, x=1, y=2): ...
> > So, what will this syntax signify? If the single-star stands for
> > "arbitrary positional arguments", how will the body of foo access
> > them? Sorry if these have been well covered already, but I read back
> > through this thread and couldn't find them.
> No, *args stands for arbitrary positional arguments.
> The unadorned * stands for "anything after this must be passed as a keyword".
> It has not yet been specified what would happen to additional
> positional arguments that get passed in anyway. (Swallow or raise an
It would be useless to swallow them (*ignored already lets you do that).
> It has not yet been specified whether the keyword-only arguments must
> each have a default. Most proposals assume not, but then do ugly
> things to support that assumption. The above suggests
> def foo(a, b=2, *, x=3, y=4): # OK
> def foo(a, b=2, *, x, y=4): # not yet decided
I first was gonna say "illegal of course" but on second though the
feature of having required keyword args is sometimes useful; I believe
I've coded such a signature myself once or twice out of **kwds and
lots of checking.
FWIW Talin, if you're writing up a PEP for this, could I ask you to
also specify a new introspection API? A function foo should have a
magic attribute foo.__signature__ which provides access to the
argument names and defaults (and types if in the future we add
argument declarations). __signature__ objects should be copyable and
mutable and the attribute should be assignable so that wrapping
decorators can copy and modify the signature of the wrapped function
onto the wrapper function (the latter is usually declared as *args,
(Ideally the __signature__ attribute on a bound method should return
the unbound method's signature modified to remove 'self'.)
Oh, other standard function attributes probably all ought to be
renamed from func_whatever to __whatever__. That applies to
'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc',
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000