On Wed, Dec 01, 2021 at 09:00:50PM -0800, [email protected] wrote:

> Steven D'Aprano
> ""If param is missing **or None**, the default if blah..."
 
> The bottom line is:
>
> you *don't actually* want the parameter to default to the value of a 
> sentinel.

Yes I do. I *do* want to be able to give a convenient sentinel value in 
order to explicitly tell the function "give me the default value".


> you *have* to use that hack because you can't express what you want the 
> default to actually be.

The point of having default values is so that the caller doesn't have to 
express what the default will actually be. If the caller has to express 
that value, it's not a default, it's a passed-in argument.

> You're doing something misleading to work around a shortcoming of the 
> language.

How is it misleading? The parameter is explicitly documented as taking 
None to have a certain effect. None is behaving here as a convenient, 
common special constant to trigger a certain behaviour, no different 
than passing (for example) buffering=-1 to open() to trigger a very 
complex set of behaviour.

(With buffering=-1, the buffer depends on the platform details, and 
whether the file is binary, text, and whether or not it is a tty.)

For historical reasons, probably related to C, the default value for 
buffering is -1. But it could have just as easily be None, or the string 
"default", or an enumeration, or some builtin constant.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/QGPPY4JLABDSKICIVJQZ5IRWMXMYAOH4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to