On 5/21/2021 9:36 AM, Petr Viktorin wrote:
On 21. 05. 21 3:23, Eric V. Smith wrote:
On 5/20/2021 3:24 PM, Ronald Oussoren via Python-Dev wrote:
One example of this is the definition of dataclasses.field:
|dataclasses.||field|(/*/, /default=MISSING/,
/default_factory=MISSING/, /repr=True/, /hash=None/, /init=True/,
/compare=True/, /metadata=None/)
Completely agree. I'm opposed to Ellipsis as a sentinel for this
reason, at least for dataclasses. I can easily see wanting to store an
Ellipsis in a field of a dataclass that's describing a function's
parameters. And I can even see it being the default= value. Not so
much default_factory=, but they may as well be the same.
And this argument also works for any other single value.
Including the original None.
(It just might not be obvious at first, before that single value starts
being used in lots of different contexts.)
I think it's a fairly obvious case, and a legitimate one to acknowledge
(the array one less so - we're talking about a "missing parameter"
sentinel, so you ought to be testing for it immediately and replacing
with your preferred/secret default value, not using it for indexing
without even checking it).
In the example above, it's fairly easy to pass "lambda: ..." as the
default_factory to work around it, and besides, the existence of rare
edge cases doesn't mean you have to force everyone into acting like
they're a rare edge case.
All the other situations where we want arguments with unspecified
default values can use ..., and the few cases where ... is a valid value
(semantically, for the API, not syntactically) can spend the time
figuring out a different API design.
Cheers,
Steve
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/EJYSP7KBD2XA26QTE2FVQP4SS2FDLPB2/
Code of Conduct: http://python.org/psf/codeofconduct/