[Python-3000] Pronouncement on parameter lists

Brett Cannon brett at python.org
Fri Apr 21 22:41:48 CEST 2006

On 4/21/06, Guido van Rossum <guido at python.org> wrote:
> 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
> > Exception?)
> 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,
> **kwds).
> (Ideally the __signature__ attribute on a bound method should return
> the unbound method's signature modified to remove 'self'.)

I already have a rough draft PEP and implementation for a
__signature__ object from a couple of months ago (sparked my thinking
on __introspects__).  I will go ahead and start another email thread
with the PEP so that details can get hashed out on that separately.

> 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',
> 'func_globals', 'func_name'.

That would be nice.  Should that be tossed into PEP 3100 for now so it
isn't lost?


More information about the Python-3000 mailing list