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

Jim Jewett jimjjewett at gmail.com
Tue Apr 18 23:52:47 CEST 2006


On 4/17/06, Talin <talin at acm.org> wrote:

>    def func( first, second=default, third ):

> ... what's the point of supplying a default for the second
> parameter, but not the third?

You may be wrapping an external library.  (Or at least a well-known API.)

I'll grant that the second argument probably ought to have been third,
but with an existing library, it often isn't.  The real choices are

    def func(first, second, third):
        # Everyone supplies the junk second on every call

    def func(first, second=default, third=sentinel):
        if third is sentinel:
            raise ValueError("Need a real 'third' key")

    def func_newname(first, third):

none of which are very satisfying.

That said, I'm not sure the use case is common enough to justify the confusion.

-jJ


More information about the Python-3000 mailing list