[Python-3000] Cleaning up argument list parsing (was Re: Morewishful thinking)

Guido van Rossum guido at python.org
Wed Apr 19 23:48:52 CEST 2006


On 4/19/06, Terry Reedy <tjreedy at udel.edu> wrote:
>
> "Guido van Rossum" <guido at python.org> wrote in message
> news:ca471dc20604190650x39efc500p503807aa757c25a3 at mail.gmail.com...
> > I once considered and rejected this syntax since another logical
> > interpretation would be that any positional arguments are accepted but
> > *ignored*.
>
> I was about to suggest that perhaps this is how it should be interpreted
> ;-).
>
> Perhaps it is too much to use syntax to indicate whether positional args
> should be silently ignored or raise an exception.  Given
>
> def f(*ignored, a, b='yes'): <body>
>
> positional args will be ignored if 'ignored' if never referenced again.  To
> raise an exception, just add
>
>   if ignored: raise TypeErrror("Positional args not allowed")
>
> Given that keyword only functions should be fairly rare (given that we have
> survived thus long without), is a syntactic abbreviation needed?

You're right. This currently doesn't work because *args must be last
(except for **kwds). but we're already considering an addition that
allows kwd=default following *args; an explicit check for args==() is
easy enough then.

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list