On 26.05.20 06:03, David Mertz wrote:
On Mon, May 25, 2020, 11:56 PM Christopher Barker
well, yes and no. this conversation was in the context of "None"
works fine most of the time.
How many functions take None as a non-sentinel value?! How many of
that tiny numbers do so only because they are poorly designed.
None already is an excellent sentinel. We really don't need others. In
the rare case where we really need to distinguish None from "some
other sentinel" we should create our own special one.
The only functions I can think of where None is appropriately
non-sentinel are print(), id(), type(), and maybe a couple other
oddball special ones.
Seriously, can you name a function from the standard library or
another popular library where None doesn't have a sentinel role as a
function argument (default or not)?
* From the builtins there is `iter` which accepts a sentinel as second
argument (including None).
* `dataclasses.field` can receive `default=None` so it needs a sentinel.
* `functools.reduce` accepts None for its `initial` parameter
(https://github.com/python/cpython/blob/3.8/Lib/functools.py#L232).
* There is also
[`sched.scheduler.enterabs`](https://github.com/python/cpython/blob/v3.8.3/Lib/sched.py#L65)
where `kwargs=None` will be passed on to the underlying `Event`.
For the following ones None could be a sentinel but it's still a valid
(meaningful) argument (different from the default):
* `functools.lru_cache` -- `maxsize=None` means no bounds for the cache
(default is 128).
* `collections.deque` -- `maxlen=None` means no bounds for the deque
(though this is the default).
Other example functions from Numpy:
*
[`numpy.concatenate`](https://numpy.org/doc/1.18/reference/generated/numpy.concatenate.html)
-- here `axis=None` means to flatten the arrays before concatenation
(the default is `axis=0`).
* Any function performing a reduction, e.g.
[`np.sum`](https://numpy.org/doc/1.18/reference/generated/numpy.sum.html)
-- here if `keepdims=` is provided (including None) then it will passed
to the `sum` method of ndarray-sub-classes, otherwise not.
*
[`np.diff`](https://numpy.org/doc/1.18/reference/generated/numpy.diff.html)
supports prepending / appending values prior to the computation,
including None (though that application is probably rare).
_______________________________________________
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/U4U7X36COLQ776LRB4O6O4BEXDXFWHJK/
Code of Conduct: http://python.org/psf/codeofconduct/