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

Terry Reedy tjreedy at udel.edu
Thu Apr 20 03:22:42 CEST 2006


"Ian Bicking" <ianb at colorstudy.com> wrote in message 
news:4446B192.8030405 at colorstudy.com...

> I don't know if there's an advantage to presenting a signature that
> accurately describes the function; it can never *really* be accurate in
> all cases, as there can be all sorts of constraints that are impossible
> to represent in the signature (like mutually exclusive keyword
> arguments).

On the contrary ;-), we could add a parameter operator !^!, used as
def f(*prohibited, a=None !^! b=None): blah
to make the keywords exclusive and automatically raise an exception if both 
are given values, or perhaps if both are given values other than, in this 
case, None.  But do we really want to substitute signature syntax for body 
code to do this?

> But then by putting in *args to constrain arguments to
> keywords, you formally represent the keyword constraint while adding a
> very inaccurate representation of the function signature for positional
> arguments.

But I intentionally did not use '*args' but instead used '*ignored' in my 
example and also suggest '*prohibited' as a convention.  Either should be 
clear enough to a code reader if used as consistently as 'self'.  Doc 
strings should just say 'positional args prohibited'.  Introspection code 
that generates alternate signature representations from func and code 
attributes could be made convention aware.

Terry Jan Reedy





More information about the Python-3000 mailing list