On 5/28/20 3:00 AM, Greg Ewing wrote: > On 28/05/20 12:38 pm, Rob Cliffe wrote: >> why not go further (as the OP suggested as far as I recall) >> and allow the more concise >> >> def order(eggs = 4, spam ?= Spam()): >> etc. > > That clutters up the header with things that are not part of > the function's signature. All the caller needs to know is that > the spam argument is optional. The fact that a new Spam object > is created on each call if he doesn't supply one is an > implementation detail. > But default values for arguments are really part of the responsibility for the caller, not the called function. The classic implementation would be that the caller passes all of the explicitly, and implicitly defined parameters (those with default arguments). If the language allows, you could have unpassed arguments that are passed as 'not provided' and that the called function detects and fills in with a value that isn't part of the API (which is sort of what the = None default does). This can also be done in Python with the *args and **kwargs parameters where the function can detect if something was passed there.
-- Richard Damon _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/RAXOC6RCAMMDPOR7GTLBR7S4MM5U4FT2/ Code of Conduct: http://python.org/psf/codeofconduct/